PageContext,ServletRequest,HttpSession,ServletContext
ServletContext
PageContext
(页面)->ServletRequest
(请求)->HttpSession
(会话)->【ServletContext
】(应用) <context-param>
<param-name>url</param-name>
<param-value>fl.net</param-value>
</context-param>
@WebServlet(name = "userServlet",value = "/user1")
public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("doGet");
//设置响应内容
resp.setContentType("text/html;charset=utf-8");
PrintWriter printWriter = resp.getWriter();
printWriter.write("<div>doGet可以了</div>");
ServletContext servletContext = this.getServletContext();
String url = servletContext.getInitParameter("url");
System.out.println(url);
servletContext.setAttribute("appInfo","net Info");
}
}
@WebServlet(name = "testServlet",value = "/test")
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//设置响应内容
resp.setContentType("text/html;charset=utf-8");
PrintWriter printWriter = resp.getWriter();
printWriter.write("<div>doGet可以了</div>");
ServletContext servletContext = this.getServletContext();
Object appInfo = servletContext.getAttribute("appInfo");
System.out.println("appInfo:"+appInfo);
}
}