How Java Server Page (JSP) works in Java

Java Server Page


JavaServerPages (JSP) is a platform-independent web application programming language developed by Sun Microsystems. JSP is a popular alternative to ASP as it is less verbose than ASP. Unlike ASP, JavaServer Pages do not require any precompilation before deployment.

How JSP Works

JSP stands for Java Server Page. JSP's are used to develop dynamic web applications. JSP's are introduced to overcome the disadvantages of servlets. In the MVC (Model View Controller) design Jsp's are used for view and servlets are for controller purpose.

Jsp's are translated into servlets at runtime. Each Jsp is translated and cached for re-usability until any modification is done for original Jsp. So, the jsp pages are relatively faster.

Jsp pages are java code in HTML pages. In Jsp you need to insert java code by using JSP tags such as scriptlet and expression. So, It is easier for developers to write code in jsp than servlets.

There are nine implicit objects in jsp like request, response, session, application, config, page, pageContext, exception and out. JSP Engine creates these objects during the translation phase.

Advantages of JSP:

  • In jsp, we can easily separate the presentation code with business logic. In the servlet, we need to combine both.
  • In servlets, the println statement is used to present the HTML code which is very difficult for developers.
  • Jsp pages are easy to maintain.
  • We can use exception handling feature as it is one of the nine implicit objects.
  • We can write servlet code in jsp pages.
  • Jsp's are cached for reusability, So they are faster than the servlets.

Post a Comment