Jsp and servlet
I wrote "getting started with servlet" last month. Today I will explore the jsp stories.
§ Review
1. What is a Web application?
2. What is Servlet? What is the difference between Servlet and general Java programs?
3. What is JSP and what is the relationship with Java?
4. What are the similarities and differences between JSP and Servlet?
5. What are the main purposes of JSP and Servlet?
§ Family members
JSP: Java server Pages is a dynamic web page Technical Standard promoted by sun and jointly established by many companies. It inserts a JSP tag and a Java program (Scriptlet) into the HTML code to form a JSP interface with the extension. JSP. When the client requests a JSP file, the web server executes the JSP file and returns it to the customer in HTML format. JSP is a high-level dynamic web page standard built on servlet IQ. In terms of concept, JSP has no new things compared with servlet. It can be said that the concept is the same, but the implementation method is slightly different. Therefore,JSP is a variant of servlet.
§ JSP Running Mode
.JSP files are compiled when they are called for the first time.For example, the test. jsp file will be compiled into the test_jsp.java file during the first call, and then compiled into a. class file like the servlet File compilation process. After that, if another customer needs to request the JSP page, the JSP page does not need to be re-compiled but directly executes the. class file that has been compiled for the first time. The following uses a sequence diagram to further understand the call and compilation process of JSP files:
Advantages of JSP
1. One compilation, multiple and multiple operations
The JSP script language is a Java language, which has all the features of the Java language. As shown in the process in, after the JSP file is compiled, when a customer requests the page again, JSP does not need to be re-compiled, but is directly executed. class file, so the execution efficiency will be particularly high.
2. Component reusability and platform independence
The reusable and cross-platform javaBeans and Ejb components provide convenience for JSP program development. We can put complicated processing programs into these components, in this way, we use these components multiple times, greatly reducing repeated code rewrites on JSP pages, improving efficiency and enhancing code reusability.
3. Reduce coupling and increase the security of source code
With JSP technology, web page developers can use HTML and xml identifiers to design and format the final page, and use JSP scripts or identifiers to generate dynamic content on the page, the statements that generate dynamic content are generally encapsulated in the JavaBean, ejb, or JSP script segments, so that the work of page designers and page programmers can be synchronized. In addition, by viewing the source file on the client, we can't see the JSP-identified statement or the encapsulated code in the component. This achieves a decoupling function similar to three layers and effectively protects the source code.
§ Combined use of JSP and servlet
When we use servlet to process a large amount of HTML text (such as HTML statements for splicing tables), it is not only a large number of tasks, but also not conducive to the maintenance and expansion of the later stage, therefore, JSP technology is used to process the front-end interface effects, while servlet technology is used for Program Logic Control.
§ Differences between JSP and servlet
JSP technology is the development of servlet technology, so it is essentially a simple servlet method. The biggest difference between the two lies in that the servlet application logic is in the Java file and is completely separated from the HTML in the presentation layer. JSP combines Java and HTML into a file with the extension. JSP. Therefore, in practical applications, JSP is used to generate dynamic web pages, and servlet is used to control business processes, that is, business logic. Therefore, JSP focuses on views, while servlet focuses on logical control.
Therefore, which technology is used in web construction for careful and detailed prior planning, and website construction is not just a technical issue, therefore, our colleagues who are studying and comparing JSP and servlet should pay more attention to the essence of their ideas, because the technology will be outdated, but the thoughts will survive for a lifetime.