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) ;   
  • 相关阅读:
    PHP 函数大集合
    PHP 单词集合
    PHP 常用函数集合
    Linux 服务器中搭建环境
    windows下cmd中命令操作
    TP中的AJAX返回ajaxReturn()
    PHP面试题
    CI表单验证
    CI数据库操作_查询构造器类
    react 的核心思想 【声名式】Declarative 的理解
  • 原文地址:https://www.cnblogs.com/gwq369/p/5318428.html
Copyright © 2011-2022 走看看