Web Development in J2EE Using the MVC Design Pattern - Java Server Pages (JSPs) Resolve Servlet Issues
(Page 3 of 5 )
The introduction of Java Server Pages (JSPs) was developed to alleviate many of the problems encountered with Java Servlets. JSPs are an extension to the Java Servlet technology. Stating it succinctly, a JSP’s life cycle ends as a servlet so they are a natural fit when paired with servlets. JSP pages are text documents containing a .jsp extension, and represent a combination of static HTML and XML-designed tags and scriptlets. The tags and scriptlets encapsulate business logic and generate content for the pages. The .jsp files are processed and converted to Java class files, then subsequently executed indirectly by a Web container.
Many JSP advantages exist, including the following:
- JSPs are compiled rather than interpreted, thereby enhancing performance.
- JSPs support scripting and offer full access to the Java language.
- JSPs can be designed as custom tags.
JSP Model 1 and Model 2 Architectures
Two separate JSP technological approaches exist for creating Web applications.
- JSP Model 1 Architecture
- JSP Model 2 Architecture
Several differences exist between the two technologies. The prime difference lies in how the request is processed. With Model 1 architecture, a single JSP manages all requests with responsibility for displaying and returning responses to the client. In contrast, the Model 2 architecture differs in that the request is intercepted by a servlet, herein now referred to as a controller servlet. This servlet manages incoming requests and makes the determination as to how to delegate the request to an appropriate Java Bean or Enterprise Java Bean for further processing. Upon completion of the given task, the servlet calls a specific JSP to return results to the client. Consider the following:
The client browser forwards a request directly to a JSP rather than a servlet. This preserves the concept of separating presentation from logic, whereas forwarding a request to a servlet does not. Sending a client request to a JSP allows the servlet to execute front-end processing such as user-authentication and authorization before forwarding the request to an object (Java Bean or EJB) for further processing. Upon completion, a JSP returns the results/response to the client. Notice how the Web server component utilizes servlets and Java Server Pages to process all client requests.
Next: Applying the Model/View/Controller Design Pattern >>
More Java Articles
More By Dwight Peltzer