Signup/Sign In

Introduction to JSP

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.

In the end a JSP becomes a Servlet

JSP pages are converted into Servlet by the Web Container. The Container translates a JSP page into servlet class source(.java) file and then compiles into a Java Servlet class.

JSP to Servlet Transformation

Why JSP is preffered over servlets?

  • JSP provides an easier way to code dynamic web pages.
  • JSP does not require additional files like, java class files, web.xml etc
  • Any change in the JSP code is handled by Web Container(Application server like tomcat), and doesn't require re-compilation.
  • JSP pages can be directly accessed, and web.xml mapping is not required like in servlets.

Advantage of JSP

  • Easy to maintain and code.
  • High Performance and Scalability.
  • JSP is built on Java technology, so it is platform independent.