JSP technology is used to make web applications the same as Servlet technology did. It may be a concept as an extension to Servlet as it gives extra capability than servlet which includes expression language, JSTL, etc.
A JSP web page includes HTML tags and JSP tags. The JSP pages are less difficult to preserve than Servlet due to the fact we can separate designing and development. It gives a few extra capabilities which include Expression Language, Custom Tags, etc.
JavaServer Pages frequently serve the same reasons as programs executed using the Common Gateway Interface (CGI). But JSP provides some benefits in differentiation with the CGI.
Finally, JSP is an essential part of Java EE, a fully completed platform for enterprise-class applications. This indicates that JSP can play a part in the simplest applications to the most complex and demanding.
Some benefits of JSP over Servlet are given below check now:
1. Extension To Servlet
JSP technology is the add-on to Servlet technology. We can make use of all the attributes of the Servlet in JSP. In addition to this, we can also make use of implicit objects, already defined tags, expression language, and Custom tags in JSP, and it makes JSP development simple.
2. Can be Maintained Easily
JSP can be simply handled because we can easily distinguish our business logic from presentation logic. In Servlet technology, we combine our business logic with the presentation logic.
3. Early Development: Don’t need to recompile and redeploy
If the JSP page is changed and updated, we don't want to recompile and redeploy the project. The Servlet code wants to be upgraded and recompiled if we have to edit the look and feel of the application.
4. Not much code like Servlet
Many tags can be used in JSP such as action tags, JSTL, custom tags, etc. that bring down the code. Additionally, we can make use of EL, implicit objects, etc.
Some Phases which follow JSP pages:
Note: jsplnit(), _jspService() and jspdestroy() are the lifecycle ways of JSP
As depicted withinside the above diagram, the JSP web page is translated into Servlet via way of means of the assist of JSP translator. The JSP translator is part of the net server that is chargeable for translating the JSP web page into Servlet. After that, the Servlet web page is compiled using the compiler and transformed into the magnificence file. Moreover, all of the techniques that Class in Servlet are finished on JSP later like initialization, committing reaction to the browser, and destruction.
To create the initial JSP page, you have to write down some HTML code which is given below, and save it by .jsp extension.
And then saved this file as index.jsp. Submit it in a folder and paste the folder in the web-apps directory in apache tomcat to process the JSP page.
index.jsp
JSP where we are making use of the scriptlet tag to put Java code in the JSP page we have created an example let's see. The Scriptlet tag will be learned later.
<html> <body> <% out.print(2*5); %> </body> </html>
It will give 10 on the browser.
Follow the below-given steps to implement this JSP page:
No, there is no need for directory structure if you don't have class files or TLD files. For instance, submit JSP files in a folder straight forward and deploy that folder. It will start processing easily. However, if you are making use of Bean class, Servlet, or TLD file, the directory structure is needed.
The directory structure of the JSP page is identical to Servlet. We hold on the JSP page exteriorly the WEB-INF folder or in any directory.