zoukankan      html  css  js  c++  java
  • 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);
    }
    }

  • 相关阅读:
    屏蔽右键
    无法解析类型 java.lang.Object。从必需的 .class 文件间接引用了它
    屏蔽右键
    Servlet的三个基本方法
    应用HttpClient来对付各种顽固的WEB服务器 摘抄
    Apache xmlrpc
    利用缓存机制快速读取XML文件数据
    JDBC连接MySQL
    HttpClient入门
    5款主流NoSQL数据库全方位横评
  • 原文地址:https://www.cnblogs.com/Nick7/p/10759834.html
Copyright © 2011-2022 走看看