前言

jsp本质上是一个servlet,而在jsp中有九个不用声明就可以使用的对象,我们叫他隐含对象。本文基于上文所写,如有需要可查看上一篇文章javaWEB总结(11):JSP简介及原理.

打开上次使用的login_jsp.java文件

    /*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.54
* Generated at: 2016-11-26 07:51:43 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp; import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*; public final class login_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent { private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory(); private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants; private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager; public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
} public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
} public void _jspDestroy() {
} public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException { final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.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; out.write("\r\n");
out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\r\n");
out.write("<title>my first jsp</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\t");
out.write("Hello World") ;
out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}

我们只看下面这段代码

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException { //参数中定义了两个隐含变量 request和 response //下面定义了六个隐含变量 pageContext,session,application,config,out,page   final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this; //………………………… //<%%>中的代码 //…………………………
 }

可以看到共有八个隐含对象

(1) request: HttpServletRequest的一个对象;

(2) response: HttpServletResponse的一个对象;(页面中几乎不用)

(3) pageContext: 页面的上下文,是PageContext的一个对象,可以从中获取其他8个隐含对象,也可以从中获取当前页面的其他信息(可参考如下API中PageContext对象的方法);(自定义标签时使用)

Method Summary
abstract  void forward(String relativeUrlPath)

           This method is used to re-direct, or "forward" the current ServletRequest and ServletResponse to another active component in the application.
 ErrorData getErrorData()

          Provides convenient access to error information.
abstract  Exception getException()

          The current value of the exception object (an Exception).
abstract  Object getPage()

          The current value of the page object (In a Servlet environment, this is an instance of javax.servlet.Servlet).
abstract  ServletRequest getRequest()

          The current value of the request object (a ServletRequest).
abstract  ServletResponse getResponse()

          The current value of the response object (a ServletResponse).
abstract  ServletConfig getServletConfig()

          The ServletConfig instance.
abstract  ServletContext getServletContext()

          The ServletContext instance.
abstract  HttpSession getSession()

          The current value of the session object (an HttpSession).
abstract  void handlePageException(Exception e)

           This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.
abstract  void handlePageException(Throwable t)

           This method is intended to process an unhandled 'page' level exception by forwarding the exception to the specified error page for this JSP.
abstract  void include(String relativeUrlPath)

           Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.
abstract  void include(String relativeUrlPath,
boolean flush)


           Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread.
abstract  void initialize(Servlet servlet,ServletRequest request,ServletResponse response,
String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)


           The initialize method is called to initialize an uninitialized PageContext so that it may be used by a JSP Implementation class to service an incoming request and response within it's _jspService() method.
 BodyContent pushBody()

          Return a new BodyContent object, save the current "out" JspWriter, and update the value of the "out" attribute in the page scope attribute namespace of the PageContext.
abstract  void release()

           This method shall "reset" the internal state of a PageContext, releasing all internal references, and preparing the PageContext for potential reuse by a later invocation of initialize().

(4) session: 代表游览器和服务器的一次会话,是HttpSession的一个对象;

(5) application: 代表当前web应用,是ServletContext的一个对象;

(6) config: 当前jsp对应的servlet的ServletConfig对象,需要访问当前jsp配置的初始化参数(如下);(几乎不使用)

<servlet>
<servlet-name></servlet-name>
<jsp-file>
<!-- 与java文件不同在于此标签,填写jsp文件的具体路径
,如WebContent下的index.jsp
则填写/index.jsp
-->
</jsp-file>
</servlet> <servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>

(7) out: JspWriter的一个对象,调用out.println()可以直接将字符串打印到游览器上;

(8) page: 指向当前JSP对应的Servlet对象的引用,但为Object类型,只能调用Object对象的方法;(几乎不使用)

第九个隐含对象

exception:在声明了page指令的isErrorPage="true"时才可以使用(如下);

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%> <!-- 此处声明了page的isErrorPage -->
<%@ page isErrorPage="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>my first jsp</title>
</head>
<body>
<% out.write("Hello World") ;
exception.getMessage(); %>
</body>
</html>

作用域范围

pageContext--> request--> session--> application 对属性的作用域从小到大。

javaWEB总结(12):JSP页面的九个隐含对象的更多相关文章

  1. jsp上的九个隐含对象

    首先说一说件jsp的原理.jsp被认为最经典的解释是  “嵌入了java 代码的html”. 在网上查了一些资料,和我本身对jsp的认识,总结如下: jsp本质上是一个servlet,继承自 当第一次 ...

  2. JSP数据交互——九大内置对象及其方法详解(一)

    ①既然说到JSP内置对象,那么什么是JSP内置对象呢? 解析:JSP内置对象,就是在编写JSP页面时,不需要做任何声明就可以直接使用的对象. 如下代码片段:  <% int[]  value  ...

  3. javaweb之jsp的九个隐含对象与基本语法

    1.在页面上可以不用声明直接使用的对象称为jsp页面的隐含对象.使用<% %>编写的java代码在_jspService方法中,如下: public void _jspService(fi ...

  4. 【JavaWEB SSH】jsp页面传值后台Controller 部分值绑定不上实体类

    //前端ajax代码 1 var oldpassword = $('#old_password').val(); var password = $('#L_pass').val(); var user ...

  5. JSP中的九大内置对象

    JSP九大内置对象 pageContext 存东西 Request 存东西 Response Session 存东西 Application(servletContext) 存东西 config(se ...

  6. jsp页面元素和内置对象

    java server pages其根本是一个简化的servlet设计.实现了在java当中使用html标签.javaEE标准 一.页面元素 1.静态内容 html.js.css相关标签元素. 2.指 ...

  7. Jsp的九个隐含对象

    JSP的9个隐含对象(内置对象) 不需要预先声明,就可以在jsp或者表达式中随意使用 out javax.servlet.jsp.JspWriter类型,代表输出流的对象.作业域:页面的执行期. re ...

  8. EL表达式的语法介绍及九大隐含对象

    一. 简介 > JSP表达式 <%= %> 用于向页面中输出一个对象. > 到JSP2.0时,在我们的页面中不允许出现 JSP表达式和 脚本片段. > 使用EL表达式来代 ...

  9. Idea中JSP页面中out内置对象报错out.println标红问题

    问题如图: 解决方法: 导入jar包 1.在pom.xml的<dependencies>里面复制 <dependency> <groupId>javax.servl ...

随机推荐

  1. window.onload多个共存 - 借鉴jQuery.noConflict的思路

    一.背景  window.onload方法只能存在一个,如果多次赋值给window.onload,则后者会覆盖前者. 二.浅谈jQuery.noConflict的实现方式 1)源代码 // 简化抽离出 ...

  2. OGG学习笔记02-单向复制配置实例

    OGG学习笔记02-单向复制配置实例 实验环境: 源端:192.168.1.30,Oracle 10.2.0.5 单实例 目标端:192.168.1.31,Oracle 10.2.0.5 单实例 1. ...

  3. NodeJS Stream 三:readable

    什么是可读流 可读流是生产数据用来供程序消费的流.我们常见的数据生产方式有读取磁盘文件.读取网络请求内容等,看一下前面介绍什么是流用的例子: const rs = fs.createReadStrea ...

  4. AI(三):微信与luis结合(上)

    目录 基本原理 公众号申请及配置 验证服务器有效性 微信请求消息类型 基本原理 基本原理如上图:腾讯微信服务器就相当于一个转发服务器,终端(手机.Pad等)发起请求至微信服务器,微信服务器然后将请求转 ...

  5. CKPlayer 只调用HTML5播放器时全屏问题 这只是Chrome浏览器的渲染bug

    如题,在系统中使用CKPlayer播放器,一切顺利,偶然发现没有全屏按钮, 正常的全屏按钮是这样的: 经过一步步调试,发现问题出在iframe, 当视频页面在iframe内时,全屏按钮不显示了,这个和 ...

  6. shell 读取文件

    #!/bin/bash content=`cat test.txt` echo "begin" for i in $content do echo $i done 读取前10行 t ...

  7. nginx如何配置网页错误页面

    首先要在http模块中加入 fastcgi_intercept_errors on; 其次要在server模块中加入 error_page 403 404 /40x.html; location = ...

  8. SpringMVC实现注解式权限验证(转)

    SpringMVC学习系列(9) 之 实现注解式权限验证   对大部分系统来说都需要权限管理来决定不同用户可以看到哪些内容,那么如何在Spring MVC中实现权限验证呢?当然我们可以继续使用serv ...

  9. GC(垃圾回收)

    Java程序的内存分配和回收都是由JRE在后台自动进行的.JRE会负责回收那些不再使用的内存,这种机制被称为垃圾回收GC.通常JRE会提供一条超级线程来进行检测和控制,一般都是在CPU空闲或内存不足时 ...

  10. centos6.5 安装zabbix

    实验说明: 操作系统: CentOS6.5 64位 Web环境: Apache Mysql PHP zabbix版本: LTS 2.2.10 Linux服务器IP: 10.0.0.2 Linux客户端 ...