1.JSP Technology
JSP is Sun provides dynamic web resource development technology. In order to solve the problem of spelling HTML content CSS and JS content in a servlet, Sun provides such a technology. If the servlet is nesting HTML in Java, then JSP is nesting Java code in HTML, making it easy to organize HTML pages
When the JSP page is first accessed, it is translated by the JSP translation engine into a servlet, from which the access to the JSP page is output by the servlet.
2.jsp syntax
(1) JSP template elements: The HTML content written in the JSP page is called the template element of the JSP, and is directly exported to the browser page by Out.write () in the translated servlet.
(2) JSP expression <%= Java expression%> in a translated servlet, after calculating the value of the Java expression, it is output to the browser
(3) JSP script fragment <% several Java statements%> in the translated servlet, directly copied and pasted to the corresponding location execution.
You can have multiple script fragments in a JSP page that can embed text, HTML tags, and other JSP elements between two or more script fragments
Code in multiple script fragments can access each other as if all the code is in a pair of <%%>
The Java statements in a single script fragment can be incomplete, but the result of a combination of multiple script fragments must be a complete Java statement
(4) JSP Declaration <%! Several Java statements%> in the translated servlet are placed in the same position as the service method, becoming a member of the class
(5) JSP annotations
The content of the <%--comment is--%> commented out by the JSP annotation, which is discarded when the JSP translation engine translates the JSP into a servlet, without this information in the translated servlet.
<%//java comments%> Java annotations are translated into servlets as JSP script fragments, and comment information is discarded when the. java file is translated into a. class file.
<!--HTML annotations and HTML annotations are exported as template elements to the browser, and the browser recognizes that HTML annotations are not displayed
Code:
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
the code that corresponds to the translation:
Package Org.apache.jsp.jsp;import Javax.servlet.*;import Javax.servlet.http.*;import javax.servlet.jsp.*;import Java.util.*;p ublic Final class Jspdemo1_jsp extends Org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent {int j=7; 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 (). GetServle Tcontext ()). 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 ("\ r \ n"); Out.write ("\ r \ n"); Out.write ("<! DOCTYPE HTML public \ "-//W3C//DTD HTML 4.01 transitional//en\" >\r\n "); Out.write ("We can see that the J variable is placed in the service sibling position as a member property. I is a local variable of the service () methodFor an expression. Direct calculation.
Dark Horse day05 JSP syntax related knowledge