• JSP stands for Java Server Pages.
• JSP is a server-side technology like Servlet that is used to develop server-side web components.
• JSP is designed as a presentation technology that allows you to render dynamic responses easily.
• JSP is a combination of HTML and Java code.
• The extension of the file must be ".jsp".
Whenever the client sends the first request to JSP, the container will do the following task:
Translates JSP to Servlet (show.jsp -> show_jsp.java)
Compiles the translated servlet (show_jsp.java -> show_jsp.class)
Loads the translated servlet class.
Creates an instance of the Translated Servlet class.
Calls the lifecycle method _jspInit() for initialization.
Invokes the lifecycle method _jspService().
Whenever the client sends the second request to JSP, then_jspService() will be called directly.
At container shutdown time, the container calls the lifecycle method _jspDestroy
The following three are the life cycle methods of JSP:
public void _jspInit()
public void _jspService(HttpServletRequest res,HttpServletResponse res)
public void _jspDestroy()
Lab 1: Working Steps :
Create a dynamic web project with the name Lab1.
Create a JSP file with the name hello.jsp.
Open the following folder, and you can delete all the content from the localhost folder.
<WORKSPACE>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\
Deploy the application to the server.
Start the server.
Send the request to show. jsp
http://localhost:12345/Lab1/hello.jsp
Open the folder.
<WORKSPACE>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Lab1\org\apache\jsp
hello_jsp.java
hello_jsp.class
Files Required For Program
1. hello.jsp
2. web.xml
1. hello.jsp
<%@ page import="java.util.Date,java.io.*" %>
<!DOCTYPE html>
<html>
<body>
<h3> Hello Guys</h3>
<% out.print("<h4>Welcome to JTC</h4>");
Date d=new Date();
out.print("Today : "+d); %>
<h3> Hai Guys</h3>
<%
int a=10;
int b=20;
int sum = a+b;
out.print("<h3> Sum : "+sum+"</h3>");
%>
<h3> OK Done !!!</h3>
<h3> SID : <%= session.getId() %> </h3>
</body>
</html>
2. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app …>
<display-name>Lab1</display-name>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>