JavaServer Pages
JavaServer Pages
JSP technology is used to create dynamic web applications. JSP pages are easier to maintain
then a Servlet. JSP pages are opposite of Servlets as a servlet adds HTML code inside Java code,
while JSP adds Java code inside HTML using JSP tags. Everything a Servlet can do, a JSP page
can also do it.
JSP enables us to write HTML pages containing tags, inside which we can include powerful Java
programs. Using JSP, one can easily separate Presentation and Business logic as a web
designer can design and update JSP pages creating the presentation layer and java developer can
write server side complex computational code without concerning the web design. And both the
layers can easily interact over HTTP requests.
JavaServer Pages often serve the same purpose as programs implemented using the Common
Gateway Interface (CGI). But JSP offers several advantages in comparison with the CGI.
Finally, JSP is an integral part of Java EE, a complete platform for enterprise class applications.
This means that JSP can play a part in the simplest applications to the most complex and
demanding.
Advantages of JSP
Following table lists out the other advantages of using JSP over other technologies
The advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual Basic or
other MS specific language, so it is more powerful and easier to use. Second, it is portable to
other operating systems and non-Microsoft Web servers.
SSI is really only intended for simple inclusions, not for "real" programs that use form data,
make database connections, and the like.
vs. JavaScript
JavaScript can generate HTML dynamically on the client but can hardly interact with the web
server to perform complex tasks like database access and image processing etc.
Lifecycle of JSP
A JSP page is converted into Servlet in order to service requests. The translation of a JSP page to
a Servlet is called Lifecycle of JSP. JSP Lifecycle is exactly same as the Servlet Lifecycle, with
one additional first step, which is, translation of JSP code to Servlet code. Following are the JSP
Lifecycle steps: