Introduction to JSP

In this post, you will learn:

  • What are the limitations of servlet?
  • What is JSP?
  • How servlet limitations are removed by JSP?
  • What is the processing model of JSP?

Limitations of servlet:

Servlet as web application development technology has following drawbacks:

1. Developing web applications using servlet is unproductive i.e. a lot of code need to written even for simple tasks.

2. A servlet is responsible for dynamic content generation as well as presentation. This intermixing of dynamic content generation logic with the presentation logic, creates maintenance problem. Each time presentation (HTML) is changed, Servlets need to be modified.

JSP and the automation of servlet:

Java Server Pages (JSP) is the extension of servlet which facilitate productive development of dynamic web applications in Java. JSP removes the above drawbacks of servlets by completely changing the web application development model. In a servlet, HTML is generated from the program whereas in JSP, request processing logic is written to the HTML with the help of special tags. Each JSP page is translated by the server into a servlet as described by the following diagram:


Description of the diagram:

1.0 – Client sends first request for a JSP page.

1.1 – Using the JSP page a servlet is generated by a server component. This servlet contains the request processing logic of the JSP and auto generated statements to write the static HTML contents to the output stream.

1.2 – The translated servlet is compiled.

1.3 – An object of the generated servlet class is created and initialized.

1.4 – Request processing method _jspService(request,response) is invoked on the servlet object.

1.5 – Contents dynamically generated by _jspService(request,response) method, are sent as response to the client.

2.0 – Subsequent requests are sent for the JSP page.

2.1 – Servlet object created for the JSP is identified.

2.2 – Request processing method _jspService(request,response) is invoked on the servlet object.

2.3 – Contents dynamically generated by _jspService(request,response) method, are sent as response to the client.

Note:- If a JSP page is modified after translation then its servlet is regenerated when next request is sent for it.

Advantages of the JSP over servlet:

1. JSP increases the productivity of the application programmers as they are only required to provide the processing logic. All the repetitive tasks such as defining classes & request processing methods, and writing static HTML contents to the output stream, are automated.

2. Maintenance is simplified. Static HTML contents or request processing logic can be changed on the fly because of the automated translation.

If you have read all the posts of servlets and practised their concepts then you would have understood the above limitations of the servlet. You can now appreciate the ease of development offered by the JSP but for that you need to understand the relation of _jspService(request,response) method to the servlet. In servlet, there was no such method!

If you have noticed this method in the diagram and this question came to your mind as well then you are on the right track. You have developed the conceptual thinking. The next post, has the answer of your question.

Its time to recap the main concepts:

  1. JSP is the extension of servlet which automates the creation of servlet.
  2. By the automation of servlet, productivity of the programmers is increased and maintenance is simplified.
If you like the post, then share it...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn