首页 > 其他分享 >servletContext应用

servletContext应用

时间:2023-01-10 22:33:40浏览次数:41  
标签:应用 url resp req HttpServletResponse servletContext context Override

 

配置初始化参数

<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

相关文章