servletContext应用

 

配置初始化参数

<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(文件流)

 

 

posted on 2023-01-10 22:27  大风吹过12138  阅读(23)  评论(0)    收藏  举报

导航