First, JSP
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.
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=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+ "/";
} 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);
else log (T.getmessage (), t);
}
} finally {
_jspxfactory.releasepagecontext (_jspx_page_context);
}
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
JSP directives
JSP tags
JSP built-in objects
Getting Started with JSPs