配置初始化参数
<context-param> <param-name>url</param-name> <param-value>woshishabi:;</param-value> </context-param>
获取并输出
public class ServletDemo03 extends HelloServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletContext context=this.getServletContext(); String url=context.getInitParameter("url"); resp.getWriter().println(url); }
public class ServletDemo04 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletContext context=this.getServletContext(); context.getRequestDispatcher("/gp").forward(req,resp);//请求转发 } }
请求转发和重定向
Properties类可以和文件输入流配合使用,
load(文件流)
标签:应用,url,resp,req,HttpServletResponse,servletContext,context,Override From: https://www.cnblogs.com/guojianglong/p/17041561.html