(1) JSP is essentially a servlet. When a user sends a request to a specified servlet, the servlet dynamically generates an HTML page using the output stream, includes every static html tag and all the content that appears on the HTML page.
(2) a jsp page consists of two parts:
Static part: standard HTML tags, static page content, which is the same as static html pages.
Dynamic part: Content controlled by Java programs, which are dynamically generated by Java programs.
(3) Compile a simple JSP page step
Set the default encoding format for JSP pages in myeclipse or eclipse: Windows-> preference-> myeclipse-> files and eitors-> JSP set encoding to UTF-8 and then apply
<Body>
This is my first JSP page <br>
<% Out. println (new date (); %>
</Body>
Explanation: JSP is actually a simplification of servlet. servlet is used when JSP is used, because each JSP page in a web application is generated by the servlet container.
package org.apache.jsp;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import java.util.*;public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase implements 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.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=ISO-8859-1"); 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'); out.write('\n');String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("
The source code of this servlet mainly contains three classes:
Init (): Initialize the JSP/servlet method.
Destory (): method before JSP/servlet destruction
Service (): method used to generate user requests.
(4) Summary of JSP Working Principles
1. jsp files must be run on the JSP server
2. jsp files must generate servlets before execution
3. The first visitor to each JSP page is very slow, because the JSP must be compiled into a Servlet
4. The visitor of the JSP page does not need to install any client or even run the Java Runtime Environment, because the JSP page is delivered to the client as a standard HTML page.