保存JSP页面状态的4个内置对象
2017-01-12 17:15
330 查看
我们必须清楚,真正在Java Web服务器内运行的是用Java语言实现的Servlet类,程序员编写的JSP页面只是Web服务器生成一个Servlet类的“材料”。根据JSP页面生成Servlet类,然后由Servlet提供HTTP服务。
当我们把Web项目部署到Tomcat服务器上,而且创建了一个JSP页面,就会在Tomcat的work \Canalina\localhost\项目名称\org\apache\jsp路径下,找到JSP页面生成的Servlet类文件。在文件中可以看到如下部分代码:
从Servlet类代码中可以看出,Web服务器执行Servlet类时,因为先定义了8个对象(JSP页面的Java脚本中可以使用的是9个内置对象,只有当页面的page指令的isErrorPage属性为true时,才可以使用exception对象),然后再处理JSP页面内容,所以这9个对象在执行JSP页面的Java脚本时都可以使用。其中,有4个对象是用于保存JSP页面状态的。
pageContext对象根据当前用户的请求和服务器的响应,保存当前项目在服务器中所处的环境(上下文),这个环境是项目中的各个页面共享的。
PageContext pageContext = null;
pageContext = _jspxFactory.getPageContext(this, request, response,null, true, 8192, true);
application对象根据pageContext所代表的环境,保存当前项目(一个Web应用)中的一些公用的数据,这些数据可以被该项目中的所有JSP页面共享。
ServletContext application = null;
application = pageContext.getServletContext();
onfig对象根据pageContext所代表的环境,保存从web.xml文件中读取的环境设置和服务器配置信息。
ServletConfig config = null;
config = pageContext.getServletConfig();
session对象也是根据pageContext所代表的环境,保存一个各户端在该项目中的一个活动(会话)的信息。
HttpSession session = null;
session = pageContext.getSession();
当我们把Web项目部署到Tomcat服务器上,而且创建了一个JSP页面,就会在Tomcat的work \Canalina\localhost\项目名称\org\apache\jsp路径下,找到JSP页面生成的Servlet类文件。在文件中可以看到如下部分代码:
//用于用户请求的方法 public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=utf-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; //以下是对JSP页面内容的处理 out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n"); out.write("<html xmlns
从Servlet类代码中可以看出,Web服务器执行Servlet类时,因为先定义了8个对象(JSP页面的Java脚本中可以使用的是9个内置对象,只有当页面的page指令的isErrorPage属性为true时,才可以使用exception对象),然后再处理JSP页面内容,所以这9个对象在执行JSP页面的Java脚本时都可以使用。其中,有4个对象是用于保存JSP页面状态的。
pageContext对象根据当前用户的请求和服务器的响应,保存当前项目在服务器中所处的环境(上下文),这个环境是项目中的各个页面共享的。
PageContext pageContext = null;
pageContext = _jspxFactory.getPageContext(this, request, response,null, true, 8192, true);
application对象根据pageContext所代表的环境,保存当前项目(一个Web应用)中的一些公用的数据,这些数据可以被该项目中的所有JSP页面共享。
ServletContext application = null;
application = pageContext.getServletContext();
onfig对象根据pageContext所代表的环境,保存从web.xml文件中读取的环境设置和服务器配置信息。
ServletConfig config = null;
config = pageContext.getServletConfig();
session对象也是根据pageContext所代表的环境,保存一个各户端在该项目中的一个活动(会话)的信息。
HttpSession session = null;
session = pageContext.getSession();
相关文章推荐
- application、session、request、page 4个JSP内置对象详细介绍
- [解决]eclipse中JSP页面的内置对象 不能引出方法的问题
- jsp页面获取后台session保存的对象
- JSP页面中内置对象out的打印方法out.print与out.write的区别
- jsp页面,jsp声明,jsp方法块,servlet,jsp内置对象
- Hello JSP!——JSP内置对象分类及属性保存范围
- jsp页面内置对象out的clear()及clearBuffer()比较
- JSP的9大内置对象及4个作用域
- jsp中9大内置对象以及4个作用域
- JSP的9大内置对象和4个作用域
- JSP页面中的标签以及内置对象request等
- JSP整理总结--9大内置对象、4个作用域
- Jsp页面内置对象不提示的问题解决
- 保存页面跳转前URL的内置对象UrlReferrer
- struts2中从数据库中读取数据,并在JSP页面中遍历保存有JavaBean对象的List对象
- jsp页面九大内置对象
- jsp页面元素和内置对象
- JSP整理总结--9大内置对象、4个作用域
- Jsp 9个内置对象和4个作用域简介
- struts2中从数据库中读取数据,并在JSP页面中遍历保存有JavaBean对象的List对象