JSP's English name is Java Server Pages, translated into Chinese is the meaning of Java Servers page, the bottom of which is a simplified servlet design, is the sum company dominated by the establishment of a dynamic Web technology standards. A Servlet is a class in the Java programming language that is used to extend the performance of a server.
The execution process and life cycle of JSP
The execution process and life cycle of the JSP, such as:
The life cycle of the servlet
The life cycle of a servlet is divided into the following three stages: first, container initialization. That init()
is, the second is to invoke service()
the method and determine how the client requests. Finally, the method is destroyed and called destroy()
.
The detailed Servlet life cycle is as follows:
Comparison of advantages and disadvantages between JSP and servlet
- JSP advantages: Improve the reusability of code, the separation of HTML code, the program is conducive to development and maintenance.
- JSP disadvantage: Not easy to track and error. Process and business logic cannot be processed.
- The advantage of servlet is to respond to the client's request, respond dynamically according to the request, the biggest advantage is as a service, control program flow, filtering and so on. C in MVC is the servlet.
- Servlet disadvantage: The servlet has too much trouble representing the view's representation logically with the JSP, which is better at displaying the work done and generating the page.
Writing the first JSP file
Write the first JSP file, in order to solve the jump path problem, can be added to the head
<% String path = request.getContextPath(); "://"":""/";%>
Such as:
Writing the first servlet program
Write the first servlet program, where you use Servlet3.0, which you do not have to configure in Web. XML, but you can set the name yourself, but you must correspond to the action in the Form form on the page. Such as:
Permanent update of this article address: https://github.com/nnngu/LearningNotes/blob/master/_posts/2018-03-22-JSP%20%E5%92%8C%20Servlet%20%E7% 9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86%e5%92%8c%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f.md
How JSP and Servlet work and life cycle