Using Jsp Technology

I wouldn’t be biased if I were to say that JSP technology is one of the most favorite presentation/web tier technologies at present. After it’s introduction in JEE technology platform, there has been considerable change in the middle tier technology and data access technology, but the front end tier is mostly built using a JSP. There may  be a wrapper in which the JSP is embedded to achieve few additional features, but the base still remains a JSP. Let us take a close look at the different uses of JSP technology at the front end tier.

Plain JSP:

By plain JSP, we are talking about a JSP not surrounded by any other technology. Here when it comes to displaying a page to the client, the response is presented using a jsp page. When the middle tier finishes its processing, it sends/forwards the result to a JSP page (XYZ.jsp). This single page does everything to present the result. This page may arrive at the final result using following options.

Details of Jsp technology can be found in this Jsp Tutorial.

JSP with Servlet:

If we look at the lifecycle of a jsp, we can see, that the jsp has actually a generated a servlet which is doing the job for us. Hence, a jsp gets converted into a servlet and the sevlet runs in the web container. But there is this interesting design pattern which uses a jsp with servlet. You may ask why do we need two servlets when a jsp can do the job of a servlet? The answer is – two important concerns are separated in this approach, viz. presentation and navigation. Jsp is used to handle the presentation business only. Servlet deals with navigation logic and the logic to call services in middle and database tier (if applicable).

Jsp Templates:

This is another way of reusing jsp code. Here we define jsp template that is in line with the standard layout of our application. Each jsp is constructed by replacing the template elements with appropriate components.

Jsp and Tiles:

Tiles take the jsp template to the next level. Tiles ask us to define a layout (s) which is (are) the base for the jsps we write. These layouts contain string and jsp elements placeholders that can be dynamically injected. There is an xml file which has a definition, that tells the container, how to construct a page. The construction includes usage of layout, and replacement of the placeholders. E.g. in layout we define placeholders for headers, footers, left menu and body of a jsp. Whenever we construct a page, we replace these place holders with appropriate pages.

Jsp and Struts:

To integrate a Jsp with Struts, we need to specify the forward path to a jsp either in struts-config.xml or in an Action class itself. Struts does allow us to use tiles. In that case, the integration is done through tiles definition. Also, Sturts has action form, which can be used while the data gets submitted to server. This form is populated and made available through the request object.

Jsp and Java Server Faces:

Java server faces creates a difference in the way we use jsp. When we integrate these two, a jsp page will contain Java Server Faces (JSF) tags. These tags are linked to server side registered components. Each component may have associated listeners, validators and converts with it. We need to be careful while integrating these two technologies as now we are having two server-side components. The first server-side components are the dynamic elements of a jsp and the second are the JSF tags. If we do not consider compilation, execution and rendering mechanism of these two technologies, then it is possible that we end up in a performance problem.

Jsp and Spring MVC:

This is similar to Struts, difference being the implementation is a bit light. Some of us may find Struts a little complicated as compared to Spring MVC, but as long as our scope is jsp integration, they are same.

Here is a good example of Jsp with Tiles and Spring MVC.

  • Share/Bookmark
JEE, Jsp, Tech Notes

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(required)

(required)