Create a new index.jsp file in the Web root directory
<%@ page language="java" contenttype="text/html; CHARSET=GBK "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><html><head><meta http-equiv="Content-type" Content="text/html; Charset=iso-8859-1 "><title>Insert Title here</title></head><body>Current system time<%out.println (new java.util. Date()); %></body></html>
Configure Web. xml
<?xml version= "1.0" encoding= "UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_ 0.xsd "id=" webapp_id " version=" 3.0 "> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></Web-app>
Start Tomcat
Browser display output
TueJun 30 20:35:20CST 2015
View the Java class file for the JSP
Index_jsp.java files can be found in D:\apache-tomcat-7.0.62\work\Catalina\localhost\ServletStudy\org\apache\jsp, the file contents are as follows
/* * Generated by the Jasper component of Apache Tomcat * Version:apache tomcat/7.0.62 * Generated at:2015-06-30 12: 35:20 UTC * Note:the Last modified time of this file is 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.*;Public final class index_jsp extends org. Apache. Jasper. Runtime. Httpjspbaseimplements Org. Apache. Jasper. Runtime. Jspsourcedependent{private static final javax. servlet. JSP. Jspfactory_jspxfactory = Javax. servlet. JSP. Jspfactory. Getdefaultfactory();private static Java. Util. Map<java. Lang. StringJava. Lang. Long> _jspx_dependants;Private Javax. El. Expressionfactory_el_expressionfactory;private org. Apache. Tomcat. Instancemanager_jsp_instancemanager;Public Java. Util. Map<java. Lang. StringJava. 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. HttpServletRequestRequest, Final Javax. servlet. HTTP. HttpServletResponseResponse) throws Java. IO. IOException, Javax. servlet. Servletexception{//jsp Implicitly object has the following object final Javax. servlet. JSP. PageContextPageContext;Javax. servlet. HTTP. HttpSessionsession = NULL;Final Javax. servlet. ServletContextApplication;Final Javax. servlet. ServletConfigConfig;Javax. servlet. JSP. JspWriter out= NULL;Final Java. Lang. Objectpage = This;Javax. servlet. JSP. JspWriter_jspx_out = null;Javax. servlet. JSP. PageContext_jspx_page_context = null;try {response. setContentType("text/html; CHARSET=GBK ");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("); out. Write("); out. Write("<meta http-equiv=\" content-type\ "content=\" text/html; charset=iso-8859-1\ " >\r\n"); out. Write("<title>insert title here</title>\r\n"); out. Write("); out. Write("<body>\r\n"); out. Write("current system time \ r \ n"); out. println(New Java. Util. Date()); out. Write("\ r \ n"); out. Write("</body>\r\n"); out. Write(");} catch (Java. Lang. ThrowableT) {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. IOExceptione) {} if (_jspx_page_context! = null) _jspx_page_context. Handlepageexception(t);else throw new Servletexception (t);}} finally {_jspxfactory. Releasepagecontext(_jspx_page_context);} }}
Summarize
- Org.apache.jasper.runtime.HttpJspBase implements the Javax.servlet.Servlet interface
- The Index_jsp class implements the Javax.servlet.Servlet interface
- As you can see, the JSP file is translated into a servlet class file by the servlet container (tomcat) and then compiled into a class file
- JSP is essentially the implementation of a servlet.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
First JSP program (JSP Primer)