It is a mechanism to create dynamic web pages by using servlet behind it. Whenever a user comes to access the jsp then the web server converts the jsp into a servlet for processing the request and providing response.
Features of jsp
1.Interpreted:- A jsp does not need explicit compilation. A programmer needs to create the jsp and store it into the context folder. Whenever the jsp gets accessed by the first user then the web server creates a servlet and complies it to create required class file. The generated servlet gets loaded into the servlet container for processing request and for providing reponse. Hence the jsp does not need explicit compilation.
2.Object based:- Jsp cannot implement inheritance and polymorphism. It can use a set of predefined objects such as request, response and out without creating those explicitly.
3.Tag based:- It can use a set of tags to perform any task in the server. These tags can be predefined or user defined.
4.User friendly:- A jsp contains java code inside html tags. The required html tags can be generated with the help of any html editor. The required java code can be inserted into the generated html tags. This makes the jsp creation faster and easier.
Possible content of a Jsp
1.Directive:- This can be used in a jsp to include or import any external file or package into the jsp.
< %@ directiveName attribute="value" %>
Ex:- <%@ page import="java.sql.*" %>
2.Declaration section:- This section can be used in a jsp to declare page scope variables and methods. This section can appear before any html tags.
<%! Declaration of variables or methods %>
Ex:- <%! int x=100; %>
3.Html tags:- These tags appear in a jsp like any ordinary html file. These can be used to represent any content to the user.
4.Scriptlets:- This section contains executable java code. This can appear in any place for any number of times in a jsp.
<% Java code %>
5.Jsp tags:- This tags can appear to perform any task in the server. This tags cannot appear inside Scriptlets.This tags follow xml syntax.
Ex:- <jsp:forward page="./test.jsp" />
6.Expression:- This can appear in a jsp to print value of a variable or result of an expression into the response.
<% = Expression or variable %>
Ex:- <H1>Welcome<% = str %></H1>
Creation process of Jsp
1.Create a file by using .jsp extension in the context folder.
2.Provide the required html tags as any ordinary html file.
3.Provide the required java code inside the html tags by using the following syntax below
<% Java code %>
Ex:- Program to show Hello JSP 5 times .
Running the application
Run the tomcat then write the below line in the Url
Here jsp is the Context path, which we mentioned in the server.xml file, which is present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) directory.
After giving the url a set a listing will come, here only one appears
As Hello.jsp,click it