first, what is
JSP
? The JSP full name is Java Server Pages, which, like Servle technology, is a technology defined by sun to develop dynamic Web resources. The biggest feature of JSP technology is that writing JSP is like writing HTML, but it can only provide static data to the user compared to HTML, while JSP technology allows to nest Java code in the page and provide dynamic data to the user. For example, output the current time in a JSP page.
Second,
JSP principle
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.
Third,
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 will be 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
20160327javaweb JSP Primer