JSP Introduction



JSP technology is used to create web application. JSP is similar to Servlet technology but we can say that it is extension to servlet

Differences between JSP and CGI :

  1. JSP allows us to embed dynamic elements in HTML page unline CGI where we need separate CGI file. It is one of the main reason why performance of the JSP is better than CGI.
  2. In CGI, When we send any script file for execution to the server then interpreter and script file will always be loaded whereas in JSP it is already compiled before it is processed by server.
  3. JSPs are built upon the Servlet so it can access all the Java Enterprises API such as JDBC, JNDI, EJB, JAXP.
  4. JSP pages can be used to handle complex business logic

First JSP Example :

<html>
<body>

Current time is : <%= new java.util.Date() %>

</body>
</html>

In the above example we can see that, we are using plain HTML and java code is embedded inside the HTML tags.

Advantages of JSP :

  1. JSP is able to use the power of Java i.e Write Once Run Anywhere
  2. JSP is easy to write than servlet though jsp’s are translated and compiled into servlets
  3. JSP uses simple understandable syntax of the HTML to make our task much easier.
  4. JSP JSP containers provide easy way for accessing standard objects and actions.
  5. JSP is used to create dynamic content by including the templates and HTML codes.
  6. JSP pages are compiled dynamically into servlets when requested, so page authors can easily make updates to presentation code