Tuesday, April 26, 2011

JSP Basics

JavaServer Pages (JSP) and Servlets are complementary technologies for producing dynamic Web pages via Java. While Servlets are the foundation for serverside Java, they are not always the most efficient solution with respect to development time. Coding, deploying, and debugging a Servlet can be a tedious
task. Fixing a simple grammar or markup mistake requires wading through print() and  println() calls, recompiling the Servlet, and reloading a Web Application.Making a grammar or markup mistake is not hard, and the problem is compounded in complex Servlets. JSP complements Servlets by helping solve this problem and simplifying Servlet development.

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 This life cycle should seem familiar and is identical to the one described for Servlets .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 HttpServletobjects 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.




No comments:

Post a Comment