05 jsp 四大域对象

domainObj.jsp

<body>
    <%
    request.setAttribute("name","request");
    session.setAttribute("name","session");
    application.setAttribute("name","application");
    pageContext.setAttribute("name","pageContext");
    
    //使用转发的方式
    //request.getRequestDispatcher("/common/receiver.jsp").forward(request, response);
    
    //使用重定向的方式
    response.sendRedirect("/jspStudy/common/receiver.jsp");
    %>
</body>

receiver.jsp

<body>
    <%
    String requestName = (String)request.getAttribute("name");
    String sessionName = (String)session.getAttribute("name");
    String applicationName =(String)application.getAttribute("name");
    String pageName= (String)pageContext.getAttribute("name");
    out.write(requestName+"<br/>");
    out.write(sessionName+"<br/>");
    out.write(applicationName+"<br/>");
    out.write(pageName+"");
    
    out.write("找到的值"+(String)pageContext.findAttribute("name"));//从小到大
    %>
</body>
Paste_Image.png

结论:
从小到大:

page域: 在同一个jsp页面中数据有效!
request域: 在同一个请求中数据有效的!
session域: 在同一个会话中数据有效的!
application域: 在同一个网站中数据有效的!
查找数据域对象值时:也是从小到大

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容