original
Understanding JSP mode 2 architecture
MVC design mode adventure
Summary: By developing a familiar web-based shopping store, you will learn how to toolize the MVC design mode and to separate the content and performance when using JSP. Govind Seshadri will show you how easy (2000 words (number of original words)). Author: Govind Seshadri aside despite the relatively recent introduction of related terms, jsp technology is good in its own way become a java technical excellence to create dynamic web content applications. Java developers love JSP because many different reasons. Some people like it brings the fact that "writing, running everywhere" is the fact that it is easy to use and help people use Java as a server-side script. But all recognizes one thing - using JSP's greatest benefits is to effectively separate content and performance. In this article, I will provide an in-depth view that gives the best content and the separation of the performance using the JSP mode 2 architecture. This mode can also be seen as a popular MVC design mode implementation in the server. Please note that you should be familiar with JSP and Servlet before starting, because I will not discuss grammar issues in this article.
So, what is the problem with servlet?
Since JSP is used to provide dynamic web content, some people may want to know why servlet is stripped with it from JSP. There is no problem with the function of servlet. It is well done well for the server, and it is suitable for this due to its important installation basis. In fact, from the structure, you can see JSP as an extension of the extended servlet with the servlet 2.1 API. Still should not use the servlet from which it should not be applied; it may not apply to everyone. For example, although the page designer can easily write JSP pages using regular HTML or XML tools, servlet is usually more suitable for background developers, they usually use some IDE - a specialized knowledge that usually requires high level programming the process of. When publishing a servlet, even if the developer must pay attention to and confirm that there is no tight coupling between content and performance. Typically, you can do this by adding a third-party HTML package such as HTMLKONA. Even though this, although there are some simple scalability for screen changes, it is still not impact on the impact of performance format itself. For example, if your performance is transformed from HTML to DHTML, you will still need to confirm that your package is compatible with this new format. In the worst case, if the package cannot be used, you may eventually pass the performance form internally internally. So, what is the solution? Just as you will see, a way will use JSP and servlet at the same time to create an application system.
Differential philosophy
Early JSP specification claims two philosophical ideas that use JSP technology to create applications. These two ideas, using terminology, JSP mode 1 and mode 2, essentially differentiated in the position where most requests occur. In the mode 1 architecture, as shown in Figure 1, the JSP page is independently responsible for processing requests and sending feedback to the client. There is still a separate content and the separation of performance, as all data access is done using beans. Although the mode 1 architecture should be very suitable for simple applications, it is not advisable to complex implementation. Any use of this structure usually results in a large number of scripts and Java code embedded in the JSP page, especially if there is a large number of requests to be processed. Although this may not be a big problem for Java developers, it is undoubtedly a problem. If your JSP page is created and maintained by the designer - this is usually in the big project. In the end, this problem will even lead to the confusion of role definitions and responsibility assignments, causing trouble that can be easily avoided.
Figure 1: JSP mode 1 structure
The pattern 2 architecture is shown in Figure 2, is a mixed scheme for dynamic content services because it uses servlet and JSP. It uses the advantages of two technologies, using JSP to generate a performance layer and servlet is responsible for performing sensitive tasks. Here, the servlet plays the role of the controller, responsible for requesting processing and generating the bean and objects to use by JSP, and determines which JSP page forwarded to the next step according to the customer's action. It is important to note that there is no processing logic within the JSP page; it is just simply responsible for acquiring objects and beans that may be created in advance, and inserting the dynamic content from the servlet in the static template. My point is that this approach generally forms the clean and thorough performance and content separation, making your developer and page designer's role and responsibility in your development team. In fact, your application is more complex, the more benefits brought by using mode 2. Figure 2: JSP mode 2 structure
In order to clarify the concept behind the mode 2, let's visit a detailed implementation of a refinement: a sample called music unbound online music store sample.
Understand the unbounded main view of the music, or the performance layer, is generated by the JSP page ESHOP.JSP for our music (see Listing 1). You will notice that this page only processes the main user interface of this app, and does not do anything to work - a best JSP script. Also note another JSP page, Cart.JSP (see Listing 2), by instruction
Listing 1 Eshop.jsp <% @ Page session = "true"%>