码迷,mamicode.com
首页 > Web开发 > 详细

JSP九大内置对象

时间:2019-04-23 23:56:04      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:4.0   gets   else   pwrite   comm   cep   vax   res   ext   

什么是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九大内置对象

标签:4.0   gets   else   pwrite   comm   cep   vax   res   ext   

原文地址:https://www.cnblogs.com/Nick7/p/10759834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!