JSP九大内置对象

Posted nick7

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSP九大内置对象相关的知识,希望对你有一定的参考价值。

什么是JSP九大内置对象
在JSP中无需创建就可以使用的9个对象,它们是:
l out(JspWriter):等同与response.getWriter(),用来向客户端发送文本数据;
l config(ServletConfig):对应JSP生成的Servlet类中的ServletConfig;
l page(当前JSP的类型):当前JSP页面的“this”,即当前对象;
l pageContext(PageContext):页面上下文对象,它是最后一个域对象;
l exception(Throwable):只有在错误页面中可以使用这个对象;
l request(HttpServletRequest):即HttpServletRequest类的对象;
l response(HttpServletResponse):即HttpServletResponse类的对象;
l application(ServletContext):即ServletContext类的对象;
l session(HttpSession):即HttpSession类的对象,不是每个JSP页面中都可以使用,如果在某个JSP页面中设置<%@page session=”false”%>,说明这个页面不能使用session。

内置对象的本来面目:
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=UTF-8\">\r\n");
out.write("<title>Insert title here</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\t");

int a = 10;

out.write("\r\n");
out.write("\t\r\n");
out.write("\t");

// 方法里面可以写什么,这里就随便写
System.out.println(a);
out.print(a++);

String name;


out.write("\r\n");
out.write("\t\r\n");
out.write("\t");
out.print(a );
out.write(" <!-- 就等同于 out.print(a) -->\r\n");
out.write("\t\r\n");
out.write("\t\r\n");
out.write("\t");
out.write("\r\n");
out.write("\t\r\n");
out.write("\t");
out.print(this.a );
out.write("\r\n");
out.write("\t\r\n");
out.write("\t");

show();
int sum = add(10,40);
System.out.println(sum);

out.print(sum);

out.write("\r\n");
out.write("\t\r\n");
out.write("\t");
out.print(add(70,10) );
out.write(" <!-- out.print(add(70,10)); -->\r\n");
out.write("\t\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 {
if (response.isCommitted()) {
out.flush();
} else {
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);
}
}

以上是关于JSP九大内置对象的主要内容,如果未能解决你的问题,请参考以下文章

JSP九大内置对象

jsp九大内置对象el11内置对象

Jsp九大内置对象

JSP九大内置对象

jsp九大内置对象

jsp九大内置对象