Web开发3:Tomcat根据JSP生成Servlet机制深度剖析及核心源代码详解

1:什么是JSP(Java Server Pages):

在传统的HTML页面中加入JAVA程序片段和JSP标签,就构成JSP网页。

JAVA程序片段可以操纵数据库,重定向网页以及发送Email等,实现建立动态网页所需要的功能。

所有程序操作都在服务器端执行,网络上传送给客户端的仅是得到的服务器的结果,这样大大降低了对客户浏览器的要求,

即使客户浏览器不支持JAVA,也可以访问JSP页面。

 

JSP的文件结构及主要标签:

 

 

 

在Tomcat的work\Catalina\localhost\目录下,存在许多由JSP文件生成的JAVA及CLASS文件。如下图。

 

以下是login.jsp文件生成的JAVA代码文件

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;

public final class login_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  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;

      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("  <body>\r\n");
      out.write("    <form action=\"/servletTest/login\" method=\"get\">\r\n");
      out.write("    \tusername:<input type=\"text\" name=\"username\"></input><br>\r\n");
      out.write("    \tpassword:<input type=\"password\" name=\"password\"></input><br>\r\n");
      out.write("    \t<input type=\"submit\" value=\"提交\"></input>&nbsp;&nbsp;&nbsp;\r\n");
      out.write("    \t<input type=\"reset\" name=\"重置\"></input>\r\n");
      out.write("    </form>\r\n");
      out.write("  </body>\r\n");
      out.write("</html>\r\n");
      out.write("\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值