JSP在进行编译的时候动态的创建了很多的内置对象,那么如果开发者知道,可以直接在JSP页面中使用这些对象。我们将这些内置的对象称之为JSP内置九大对象。
如果需要将以下的九大内置对象直接获取出来,那么可以这样做:
编写一个错误处理页面,那么请求查看翻译好的jsp文件。
1 public void _jspService(HttpServletRequest request, HttpServletResponse response) 2 throws java.io.IOException, ServletException { 3 PageContext pageContext = null; 4 HttpSession session = null; 5 Throwable exception = org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request); 6 if (exception != null) { 7 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 8 } 9 ServletContext application = null; 10 ServletConfig config = null; 11 JspWriter out = null; 12 Object page = this; 13 JspWriter _jspx_out = null; 14 PageContext _jspx_page_context = null; 15 ...... 16 }
因为在JSP中编写JSP脚本以及JSP输出表达式都会默认翻译在_jspService()那么以上该方法中定义的九大对象开发者可以任意使用。
JSP九大对象 |
Servlet类型 |
request |
HttpServletRequest |
response |
HttpServletResponse |
session |
HttpSession |
config |
ServletConfig |
application |
ServletContext |
out |
JspWriter |
page |
Object |
pageContext |
PageContext |
exception |
Throwable |