Technical Principles of JSP
JSP is a servlet extension. Servlet technology has already appeared before JSP is available. Servlet uses the output stream to dynamically generate HTML pages, including each HTML Tag and the content displayed on each HTML page.
Servlet development efficiency is extremely low because it includes a large number of HTML tags, a large number of static texts and formats. All the presentation logic, including layout, color, and images, must be coupled in Java code, which is indeed annoying. JSP makes up for this deficiency. jsp inserts Java code into the standard HTML page, and its static part does not need Java program control, java Script control is used only when information needs to be read from the database and dynamically generated based on the program. On the surface, JSP pages no longer need Java classes, and seem completely out of the Java object-oriented features.
In fact, JSP is a special form of servlet. Each JSP page is a servlet instance. The JSP page is compiled into a servlet by the system, and the servlet is responsible for responding to user requests. JSP is actually a simplification of servlet. servlet is used when JSP is used, because each JSP page in the Web application is generated by the servlet container. For tomcat, the servlet generated on the JSP page is placed under the web application corresponding to the work path.
Code of a test JSP page:
<%
Public int count;
Out. println (count ++ );
%>
When testing the page in the browser, you can see that the Count value is normally output. Every time you refresh the page, the Count value is added to 1, and the return value of the info method is also displayed.
Open multiple browsers, or even open a browser on different machines to refresh the page. It is found that the Count value of each client is completely continuous, and all clients share the same count variable. This is because: JSP page
Each servlet has only one instance in the container. The variables declared in JSP are member variables of the class, and the member variables are initialized only when the instance is created, the value of this variable will be saved until the instance is destroyed.