Introduction to JSP
JSP- Java Server Pages
Introduction
Advantages of JSP over Servlet�
1)Extension to Servlet: JSP technology is the extension to Servlet technology. We can use all the features of the Servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression language and Custom tags in JSP, that makes JSP development easy.
2) Easy to maintain: JSP can be easily managed because we can easily separate our business logic with presentation logic. In Servlet technology, we mix our business logic with the presentation logic.
3) Fast Development: No need to recompile and redeploy, If JSP page is modified, we don't need to recompile and redeploy the project. The Servlet code needs to be updated and recompiled if we have to change the look and feel of the application.
4) Less code than Servlet: In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that reduces the code. Moreover, we can use EL, implicit objects, etc.
JSP and PHP both are server side scripting languages. But here is a list of reasons why JSP is better than PHP
JSP Architecture
->Web client sends request to Web server.
-> As per the request, the Web server (here after called as JSP container) loads the page.
->JSP container converts JSP file into .java file having servlet code-Translation.
.java file is converted into .class file- compilation.
->The .class file of Servlet is executed and output of execution is sent to the client as response.
Life cycle of JSP
JSP Initialization
public void jspInit()
{
// Initialization code...
}
Typically, initialization is performed only once and as with the servlet init method, you generally initialize database connections, open files, and create lookup tables in the jspInit method.
JSP Execution
void _jspService(HttpServletRequest request, HttpServletResponse response)
{
// Service handling code...
}
The _jspService() method of a JSP is invoked on request basis. This is responsible for generating the response for that request and this method is also responsible for generating responses to all seven of the HTTP methods, i.e, GET, POST, DELETE, etc.
JSP Cleanup
public void jspDestroy()
{
// Your cleanup code goes here.
}