获取初始化参数
<!--可以配置一些web应用初始化参数-->
<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost:3306/mybatis</param-value>
</context-param>
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//读取初始化参数
ServletContext context = this.getServletContext();
String url = (String)context.getInitParameter("url");
resp.getWriter().println(url);
}
转发和重定向
doGet(){
...
// RequestDispatcher requestDispatcher = context.getRequestDispatcher("");//转发的路径
// requestDispatcher.forward(req,resp);//实现转发
context.getRequestDispatcher("").forward(req, resp);
...
}
转发(上)和重定向(下)
读取资源文件
poperties
classpath: java和resource路径
classpath路径
读取资源文件
思路: 需要一个文件流;
网友评论