JSP运行原理(二)

public void (HttpServletRequest request, HttpServletResponse response)

        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;

    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 {

      _jspxFactory = JspFactory.getDefaultFactory();

      response.setContentType("text/html;charset=gb2312");

      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("<html>\r\n");

      out.write("   <head>\r\n");

      out.write("      <title>登录成功</title>\r\n");

      out.write("   </head>\r\n");

      out.write("   <body>\r\n");

      out.write("      <h2>");

      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${sessionScope.userid}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));

      out.write("您好,欢迎登录网上书店!</h2>\r\n");

      out.write("   </body>\r\n");

      out.write("</html>\r\n");

} catch (Throwable t) {

      if (!(t instanceof SkipPageException)){

        out = _jspx_out;

        if (out != null && out.getBufferSize() != 0)

          out.clearBuffer();

        if (_jspx_page_context != null)

_jspx_page_context.handlePageException(t);

      }

    } finally {

      if (_jspxFactory != null)

_jspxFactory.releasePageContext(_jspx_page_context);

    }

}

}

从JSP被转换成的Java文件可以看出如下几点:

1) JSP文件中的内容基本都被包含在了_jspService方法中,实际上页面执行的过程就是这个方法执行的过程;

2) 页面中显示给用户的HTML信息都被转换成了out.println("XXXX")的形式;

3) _jspService方法中有两个参数requestresponse

4) 在方法中生成了如下几个对象:

    PageContext pageContext = null;

    HttpSession session = null;

    ServletContext application = null;

    ServletConfig config = null;

    JspWriter out = null;

    Object page = this;

这就是传说中的内置对象(预定义对象)。

返回给客户端的代码(通过在客户端浏览器可以查看源文件):

<html>

   <head>

      <title>登录成功</title>

   </head>

   <body>

      <h2>zhangsan您好,欢迎登录网上书店!</h2>

   </body>

</html>

 

在此文件中看不到任何JSP的代码,而是纯HTML代码。与源文件不同的地方:

【1】源文件中的page指令没有了

【2】源文件中的${sessionScope.userid}没有了,而使用zhangsan代替了原来的表达式。

浏览器把这段HTML代码解析成界面显示给用户。

这就是从你编写的JSP文件到客户端看到的结果的转换过程。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值