• Jsp九大内置对象


     九大内置对象

    •   out(JspWriter):等同与response.getWriter(),用来向客户端发送文本数据;
    •   config(ServletConfig):对应“真身”中的ServletConfig
    •   page(当前JSP的真身类型):当前JSP页面的“this”,即当前对象;
    •   pageContext(PageContext):页面上下文对象,page域对象
    •   exception(Throwable):只有在错误页面中可以使用这个对象;
    •   request(HttpServletRequest):即HttpServletRequest类的对象;
    •   response(HttpServletResponse):即HttpServletResponse类的对象;
    •   application(ServletContext):即ServletContext类的对象;
    •   session(HttpSession):即HttpSession类的对象,

    不是每个JSP页面中都可以使用,如果在某个JSP页面中设置<%@page session=”false”%>,说明这个页面不能使用session。

    在这9个对象中有很多是极少会被使用的,例如:config、page、exception基本不会使用。

    在这9个对象中有两个对象不是每个JSP页面都可以使用的:exception、session。

    原理

    JSP页面的内容出现在“真身”的_jspService()方法中,而在_jspService()方法开头部分已经创建了9大内置对象。

    public void _jspService(HttpServletRequest request, HttpServletResponse response)
            throws java.io.IOException, ServletException {
    
        PageContext pageContext = null;
        HttpSession session = null;
        ServletContext application = null;
        ServletConfig config = null;
        JspWriter out = null;
        Object page = this;
        JspWriter _jspx_out = null;
        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;
       }…
    View Code
  • 相关阅读:
    C#遍历List并删除某个或者几个元素的方法
    7月清北学堂培训 Day 4
    7月清北学堂培训 Day 3
    7月清北学堂培训 Day 2
    7月清北学堂培训 Day 1
    P1383 高级打字机
    P2401 不等数列
    P1412 经营与开发
    P1314 聪明的质监员
    2019.7.9 校内测试 T3 15数码问题
  • 原文地址:https://www.cnblogs.com/64Byte/p/12871586.html
Copyright © 2020-2023  润新知