JSP stands for “JavaServer Pages” is considered as the server side technology which is used for the creation of dynamic web application and these web based applications are platform independent. JSP technology is the same as the Servlet technology and is called as the server side technology. JSP is also referred as an extension or successor of servlet as in JSP more functions are added which may include expression language etc. So every page of JSP is first converted into servlet before manipulating the request of any client. This is done by JSP container. The difference between JSP and servlet is that JSP inserts the Java code into the HTML tags whereas servlet adds the HTML tags into the java code.
In a JSP web page we have html and JSP tags. The JSP pages can be maintained easily as compared to servlet as in the JSP pages we have the facility to separate the designing and the development. In the JSP pages we have additional features also which may include expression language or custom tag etc. JSP is actually designed for the graphical user interface of certain application. Through JSP we can have the implementation of presentation layer for any application.
JSP is a server technology in which we have the java code into the HTML tags that is we use JSP to develop such type of web pages in which java code is inserted into the HTML tags. Therefore we can say that a JSP code is just similar to an HTML with an addition of the java code. An HTML file can be converted into JSP by simply changing the extension of the file from .html to.jsp. From the above discussion we can conclude that the only difference between HTML and JSP pages is that a JSP code has java code in addition to HTML tags and in an HTML page we only have the HTML tags. In a JSP page we can have both HTML and XML. This can only be possible by using the JSP actions and various commands.
A JSP page can be converted to servlet for the processing of the request of client as JSP is the extension of servlet. This can be done by using JSP container or web container. The JSP page is first translated to servlet then it is compiled into servlet class of java. Consider the following steps that are included while converting a JSP page into servlet:
- Initially we have the JSP page with jsp extension for example abc.jsp.
- This page that is abc.jsp is translated to java and now it has an extension called .java. This page now is abc_jsp.java.
- The abc_jsp.java is then compiled to java servlet class and the page becomes abc_jsp.class
- Now we can load abc_jsp.class as abc_jsp servlet.
In this way the JSP page is converted into servlet for the manipulation of the request of client.
A JSP page can be a HTML page which is used for the dynamic development of web based applications. A dynamic content is like when we are including registration forms or check boxes or drop down menus in our web applications. There are a number of advantages of JSP over servlet:
- In a JSP page we can insert dynamic elements into the HTML and we do not have to add the HTML pages separately. And we do not need to insert additional files such as class files of java etc.
- In a JSP page we can have all the features of a servlet as JSP is the extension of servlet. These features may include custom tags, expression language and predefined tags in the JSP which makes the development of a JSP page easier.
- The execution is faster in JSP as compared to servlet.
- Dynamic web pages are easy to code as compared to servlet.
- When any change is made in a JSP page we do not need to re compile the page as these changes are be maintained or handled by the web container.
- We can also use the JSP pages in combination with servlet this will handle the business logic.
The following are some of the advantages of JSP:
- The JSP pages are easy to maintain and are easy to code also. The code of a JSP page is less because we have tags for example action tags, custom tags which reduces the code. Also we can have a number of objects in our JSP page.
- The programming language used to code a JSP page is Java. Java is a dynamic programming language which makes the JSP page portable and can be moved to other operating systems.
- There is no need of re compiling the JSP page if we have made changes in the page.
- Business logic and presentation logic can be separated.
- As there are dynamic elements therefore, performance of JSP pages is good.