zoukankan      html  css  js  c++  java
  • JSP中page和pageContext的区别

     

     转载:http://tanlan.iteye.com/blog/705801

    page java.lang.Object  对应this关键字。JSP网页本身,page对象是当前页面转换后的Servlet类的实例。从转换后的Servlet类的代码中,可以看到这种关系:Object page = this;在JSP页面中,很少使用page对象。

      pageContext  javax.servlet.jsp.PageContext 的实例,该对象代表该JSP 页面上下文,使用该对象可以访问页面中的共享数据。常用的方法有getServletContext和getServletConfig等。

    Java代码  收藏代码
    1. //使用pageContext 设置属性,该属性默认在page 范围内  
    2. pageContext. setAttribute ("page" , "hello") ;  
    3.   
    4. //使用request 设置属性,该属性默认在request 范围内  
    5. request. setAttribute ("request" , "hello");  
    6.   
    7. //使用pageContext将属性设置在request 范围中  
    8. pageContext.setAttribute("request2″ , "hello" , pageContext.REQUEST_SCOPE);  
    9.   
    10. //使用session将属性设置在session 范围中  
    11. session.setAttribute("session" , "hello");  
    12.   
    13. //使用pageContext将属性设置在session范围中  
    14. pageContext.setAttribute("session2″ , "hello" , pageContext.SESSION_SCOPE);  
    15.   
    16. //使用application将属性设置在application范围中  
    17. application. setAttribute ("app" , "hello") ;  
    18.   
    19. //使用pageContext 将属性设置在application 范围中  
    20. pageContext.setAttribute("app2″ , "hello" , pageContext.APPLICATION_SCOPE) ;   
  • 相关阅读:
    Ajax的基本使用
    Jquery--动画
    JQuery基础(选择器、事件、DOM操作)
    LinQ 创建连接、简单增删改查
    分页查询/组合查询
    分页查询、组合查询
    JavaScript
    WebForm Response和Request以及Cookie
    Response、Request、QueryString,修改,Cookies
    Repeater
  • 原文地址:https://www.cnblogs.com/gwq369/p/5318428.html
Copyright © 2011-2022 走看看