last month, I wrote "Teach you how to get started with Servlets," and today come to explore the stories about JSP.
§ Review
1. What is a Web application?
2. What is a servlet, and what is the difference between a generic Java program?
3. What is JSP, and what is the relationship to Java?
4. What are the similarities and differences between JSP and servlet?
5. What are the main uses of JSPs and Servlets?
§ A Pro
Jsp:java Server Pages is a dynamic Web technology standard developed by Sun, a company that many companies are involved in. It inserts JSP tags and Java programs (scriptlet) into the HTML code to form the JSP interface with the extension. Jsp. When a client requests a JSP file, the Web server executes the JSP file and returns it to the customer in HTML format. And JSP is a high-level dynamic Web Standard built on the servlet IQ. So conceptually, compared to Servlets, JSP has nothing new, it can be said that the concept is exactly the same, but in a slightly different way of implementation. Thus,jsp is a variation of the servlet .
How the §jsp works
. The JSP file is compiled the first time it is called, for example, the test.jsp file is compiled as a Test_jsp.java file on the first call, and then, like the compilation process of the servlet file, is compiled as a. class file. From then on, if another customer needs to request the JSP page, theJSP page does not need to be recompiled but executes the first compiled. class file directly . Let's take a time series diagram to learn more about the call and compile process for JSP files:
Advantages of §jsp
1. Compile once, run multiple times, multiple places
JSP Scripting language is the Java language, it has all the characteristics of the Java language, as shown in the process, after the JSP file is compiled, when a client requests the page again, the JSP does not need to be recompiled, Instead, it executes the. class file that was already compiled directly, so the execution efficiency is particularly high.
2. Component reusability, platform agnostic
with reusability and cross-platform JavaBeans and EJB components, which facilitates the development of JSP programs, we can put complex handlers in these components, so that by using these components many times, we greatly reduce the rewriting of duplicated code in the JSP page, improve the efficiency, Enhanced reusability of the code.
3. Reduce the coupling, increase the security of the source program code
using JSP technology, Web page developers can use HTML and XML identities to design and format the final page , use JSP scripts or identities to generate dynamic content on the page, and statements that generate dynamic content are typically encapsulated in JavaBean, EJB or JSP script segment , so that the designer of the page and the programmer of the page can work synchronously. And we in the client by looking at the source file, do not see the JSP identity of the statement , also do not see the package in the component code, so that the similar to the three-layer decoupling, effectively protect the source code.
Combination of §jsp and servlet
since we use Servlets to process large amounts of HTML text (such as HTML statements for stitching tables), not only is the task volume large, but also not conducive to later maintenance and expansion, so we deal with the front-end interface effect of the JSP technology, And the logical control of the program uses the servlet technique.
The difference between §jsp and servlet
JSP Technology is the development of servlet technology, so it is essentially a simple way for servlets. The biggest difference between the two is that the application logic of the servlet is in the Java file and is completely separated from the HTML in the presentation layer. The JSP scenario is to combine Java and HTML into a file with a. jsp extension. So in practical applications, we use JSP to generate dynamic page pages, using Servlets to control the business process, the so-called business logic . so the JSP focuses on the view, and the servlet focuses on the logic control.
Therefore, in the Web building in the end to use what kind of technology carefully detailed pre-planning, and Web site construction is not only a technical problem, so we learn and contrast JSP and servlet colleagues should pay attention to the essence of the idea, because the technology will be outdated, And thought is a lifetime.
JSP, servlet a pro