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 :
- 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.
- 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.
- JSPs are built upon the Servlet so it can access all the Java Enterprises API such as JDBC, JNDI, EJB, JAXP.
- 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 :
- JSP is able to use the power of Java i.e Write Once Run Anywhere
- JSP is easy to write than servlet though jsp’s are translated and compiled into servlets
- JSP uses simple understandable syntax of the HTML to make our task much easier.
- JSP JSP containers provide easy way for accessing standard objects and actions.
- JSP is used to create dynamic content by including the templates and HTML codes.
- JSP pages are compiled dynamically into servlets when requested, so page authors can easily make updates to presentation code