时间:2023-05-07 21:24:02 | 来源:网站运营
时间:2023-05-07 21:24:02 来源:网站运营
JSP执行过程详解:以下为转载文章:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head></head><body><%!int count = 0;synchronized void setCount() {count++; }; %><h2>欢迎阅读本文<h2><br> 本文阅读次数:<% setCount();out.println(count);%><br>i=0,计算i++=<%int i = 0;out.println(i++);%> </body></html>
这个例子的目的是为了区分在<%! %>和<%%>中定义的变量:apache-tomcat-7.0.59/work/Catalina/localhost/yourwebapp/org/apache/jsp
这些servlet的名字都是以_jsp.java结尾。下面是counter_jsp.java的具体内容:/* * Generated by the Jasper component of Apache Tomcat* Version: Apache Tomcat/7.0.59* Generated at: 2015-08-07 05:13:13 UTC* Note: The last modified time of this file was set to* the last modified time of the source file after* generation to assist with modification tracking.*/package org.apache.jsp;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import java.util.*;public final class counter_jsp extends org.apache.jasper.runtime.HttpJspBaseimplements org.apache.jasper.runtime.JspSourceDependent {int count = 0;synchronized void setCount() {count++; }; private static final javax.servlet.jsp.JspFactory _jspxFactory =javax.servlet.jsp.JspFactory.getDefaultFactory();private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;private javax.el.ExpressionFactory _el_expressionfactory;private org.apache.tomcat.InstanceManager _jsp_instancemanager;public java.util.Map<java.lang.String,java.lang.Long> getDependants() {return _jspx_dependants;}public void _jspInit() {_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());}public void _jspDestroy() {}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/">/r/n");out.write("<html>/r/n");out.write("<head></head>/r/n");out.write("<body>/r/n");out.write("/t");out.write("/r/n");out.write("/t<h2>/r/n");out.write("/t/t欢迎阅读本文/r/n");out.write("/t/t<h2>/r/n");out.write("/t/t/t<br> 本文阅读次数:/r/n");out.write("/t/t/t");setCount();out.println(count); out.write("/r/n");out.write("/t/t/t<br>/r/n");out.write("/t/t/ti=0,计算i++=/r/n");out.write("/t/t/t");int i = 0;out.println(i++); out.write("/r/n");out.write("/t/t/r/n");out.write("</body>/r/n");out.write("</html>/r/n");} 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);}}}
也许你回疑问,counter_jsp.java并没有继承HttpServlet,为什么称它们为servlet?请注意下面public final class counter_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent
public abstract class HttpJspBase extends HttpServlet implements HttpJspPage{...}
因为下面的关系,所以这些_jsp.java文件都是servlet。HttpServlet
继承者 HttpJspBase
继承者 counter_jsp
关键词:过程,执行