站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Servlets and JavaServer Pages: The J2EE Technology Web Tier

Servlets and JavaServer Pages: The J2EE Technology Web Tier

[ directory ]JSP 2.0 Specification The Difference Between Servlets and JSP

JSP Life Cycle

Much like Servlets, understanding JSP requires understanding the simple life cycle that JSP follows. JSP follows a three-phase life cycle: initialization, service, and destruction, as shown in Figure 3-1. This life cycle should seem familiar and is identical to the one described for Servlets in Chapter 2.

Figure 3-1. JSP Life Cycle

graphics/03fig01.gif


While a JSP does follow the Servlet life cycle, the methods have different names. Initialization corresponds to the jspInit() method, service corresponds to the _jspService() method, and destruction corresponds to the jspDestroy() method. The three phases are all used the same as a Servlet and allow a JSP to load resources, provide service to multiple client requests, and destroy loaded resources when the JSP is taken out of service.

JSP is designed specifically to simplify the task of creating text producing HttpServlet objects and does so by eliminating all the redundant parts of coding a Servlet. Unlike with Servlets there is no distinction between a normal JSP and one meant for use with HTTP. All JSP are designed to be used with HTTP and to generate dynamic content for the World Wide Web. The single JSP _jspService() method is also responsible for generating responses to all seven of the HTTP methods. For most practical purposes a JSP developer does not need to know anything about HTTP, nor anything more than basic Java to code a dynamic JSP.

[ directory ]JSP 2.0 Specification The Difference Between Servlets and JSP