ServletContext是容器上下文,指当前的一个web应用的上下文

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

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

  1.    //使用pageContext 设置属性,该属性默认在page 范围内
  2.   pageContext. setAttribute ("page" , "hello") ;
  3.   //使用request 设置属性,该属性默认在request 范围内
  4.   request. setAttribute ("request" , "hello");
  5.   //使用pageContext将属性设置在request 范围中
  6.   pageContext.setAttribute("request2″ , "hello" ,pageContext.REQUEST_SCOPE);
  7.   //使用session将属性设置在session 范围中
  8.   session.setAttribute("session" , "hello");
  9.   //使用pageContext将属性设置在session范围中
  10.   pageContext.setAttribute("session2″ , "hello" ,pageContext.SESSION_SCOPE);
  11.   //使用application将属性设置在application范围中
  12.   application. setAttribute ("app" , "hello") ;
  13.   //使用pageContext 将属性设置在application 范围中
  14.   pageContext.setAttribute("app2″ , "hello" , pageContext.APPLICATION_SCOPE);
  1. //使用pageContext 设置属性,该属性默认在page 范围内
  2. pageContext. setAttribute ("page" , "hello") ;
  3. //使用request 设置属性,该属性默认在request 范围内
  4. request. setAttribute ("request" , "hello");
  5. //使用pageContext将属性设置在request 范围中
  6. pageContext.setAttribute("request2″ , "hello" ,pageContext.REQUEST_SCOPE);
  7. //使用session将属性设置在session 范围中
  8. session.setAttribute("session" , "hello");
  9. //使用pageContext将属性设置在session范围中
  10. pageContext.setAttribute("session2″ , "hello" ,pageContext.SESSION_SCOPE);
  11. //使用application将属性设置在application范围中
  12. application. setAttribute ("app" , "hello") ;
  13. //使用pageContext 将属性设置在application 范围中
  14. pageContext.setAttribute("app2″ , "hello" , pageContext.APPLICATION_SCOPE);

总的来说,pageContext和page都是jsp中的隐含对象,pageContext代表jsp页面的上下文关系,能够调用、存取其他隐含对象;

page代表处理当前请求的时候,这个页面的实现类的实例。

page、pageContext、servletContext的区别的更多相关文章

  1. JSP内置对象——application,page,pageContext,config,Exception

    application对象application对象实现了用户数据的共享,可存放全局变量.application开始于服务器的启动,终止于服务器的关闭.在用户的前后链接或不同用户之间的连接中,可以对a ...

  2. PageContext ServletContext ServletConfig辨析

    上面三个东西都是什么关系呀? 先看图 注意几点 1 GenericServlet有两个init方法# 2 GenericServlet既实现了ServletConfig方法,它自己由依赖一个Servl ...

  3. <jsp:include page="${pageContext.request.contextPath/index.jsp" ></jsp:include> 引发的错误

    路径引发的错误 如下使用项目路径对jsp页面进行获取,会报javax.servlet.ServletException: File "/web/dbwx/web/public/page_to ...

  4. servletconfig和servletContext的区别

    1.servletConfig: 在Servlet的配置文件中,可以使用一个或多个<init-param>标签为servlet配置一些初始化参数.(配置在某个servlet标签或者整个we ...

  5. Ecstore后台中显示页面display,page,singlepage方法的区别?

    dispaly 显示的页面不包含框架的其他页面,只是本身的页面(使用范围:Ecstore的前端.后端). page 显示的页面包含在框架的里面(使用范围:Ecstore的前端.后端). singlep ...

  6. JAVA-Servlet-ServletConfig 与 ServletContext 的区别

    什么是ServletConfig? Servlet容器初始化一个servlet对象时,会为这个servlet对象创建一个servletConfig对象.在servletConfig对象中包含了serv ...

  7. JSP内置对象page/pageContext/Config/Exception

    Config对象 config对象实是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一 ...

  8. jsp 中 include指令 用法, <%@ include file="..."%> 和 <jsp:include page="..." flush="true" />的区别?

    原文链接https://blog.csdn.net/u012187452/article/details/51779052 1. 什么是jsp 文件? 个人理解.  jsp 是一个容器,可以将我们编写 ...

  9. Page和list的区别 mybatis

    先看一段代码 点击查看代码 @Override public Result findUserPage(PageParam pageParam) { Page<SysUser> page = ...

随机推荐

  1. DAO实例代码优化

    一般在接口的实现类中不用来实现登陆等功能,在测试类中实现并且测试. package com.beiwo.epet.service.impl; import com.beiwo.epet.dao.Mas ...

  2. C# MVC ( 将控制器的实体类注册到视图 )

    (1)控制器  代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...

  3. http://www.360doc.com/content/13/0516/22/12094763_285956121.shtml

    http://www.360doc.com/content/13/0516/22/12094763_285956121.shtml

  4. 刷CM7固件 乐padA1-07专用固件

    --------------------------------------------------------------------------------               前几天在版 ...

  5. ORA-01033: ORACLE 正在初始化或关闭 进程 ID: 0 会话 ID: 0 序列号: 0

    用了很长时间的数据库,一直都挺好,今天早上一来报这个错,开始追究原因. 1.用SYS用户登录: 2.将数据库修改为打开状态,alter database open,出现如下的错误提示: ORA-160 ...

  6. python之路-Day6

    time & datetime模块 #_*_coding:utf-8_*_ __author__ = 'Alex Li' import time # print(time.clock()) # ...

  7. centos7安装mariadb10遇到的问题解决

    4. 安装中的错误 4.1 /bin/ld: cannot find -lz /bin/ld: cannot find -lzcollect2: error: ld returned 1 exit s ...

  8. python动态获取对象的属性和方法 (转载)

    首先通过一个例子来看一下本文中可能用到的对象和相关概念. #coding:utf-8 import sys def foo():pass class Cat(object): def __init__ ...

  9. [Docker] docker 基础学习笔记3(共6篇)

    首先我们安装好了ssh server之后, 我们需要将这个容器commit,然后启动这个被commit的image. 启动方式: docker run -d -p 2222:22 /usr/sbin/ ...

  10. nw_socket_handle_socket_event解决

    http://www.bkjia.com/IOSjc/1158465.html 出现问题如下 to a parent directory scheduled for deletion nw_endpo ...