Technical Principles of JSP

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.