Master java skills

JSP Introduction

JSP stands for Jakarta Server Pages (formerly known as JavaServer Pages). JSP is a collection of technologies such as HTML, java, XML, javascript etc that helps developers create dynamically generated web pages. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses Java programming language.

To deploy and run jsp (Jakarta Server Pages), a compatible web server with a servlet container, such as Apache Tomcat or Jetty, is required.

Important points about JSPs

  • JSP stands for Jakarta Server Pages.
  • JSPs are translated into servlets
  • JSP is Server-side scripting language. Server-side scripting means that the JSP code is processed on the web server rather than the client side such as a browser.
  • Extension of jsp files is .jsp.
  • JSP page is a combination of html code, java code, and/or javascript codes
  • JSPs are used to build dynamic web applications.
  • JSP is an improved extended version of Servlet technology.

What is the need of JSPs when Servlets are already there?

Eventually, jsp files are translated into servlets. So, what is the need of jsp at all? Consider below points

  1. Servlets are html codes embedded into a java class
  2. So, it is tough to write huge html codes into java.
  3. This also reduces the readability of the code
  4. Someone who is expert in html has to know little bit of java also, if he/she wants to write servlets

Because of the above reasons, it was thought what if we reverse the process. Meaning if we could write java code into html, it will enhance the readability and html developer and java developer can work together. Since all of the above issues of servlets were taken care of in jsp technology, jsp came into existence.

Note1 -> A good jsp page is the one in which there is only html code and java code is separated from it. And jsp has custom tags using which we can completely separate out java code from it.

Note2 -> The main purpose of jsp pages is to work as view only with dynamic content.

JSP advantages over Servlets

  • JSP has a more efficient and straightforward approach for creating dynamic web pages.
  • Unlike Servlet, JSP doesn’t need to have any mapping in web.xml.
  • Web Container handles changes when changes are done in the JSP code. We don’t have to restart the server to take the changes info effect.
  • Direct access to JSP pages is possible, and hence web.xml mapping is not required.

JSP features

  1. Due to java codes, jsps are also platform independent.
  2. JSPs are easy to write and maintain
  3. Development and testing becomes fast because there is no need for recompilation and redeployment.
  4. JSP has high performance and scalability compared to other dynamic web development tools.