Java Programming_Lab 5_2 JSP
Java Programming_Lab 5_2 JSP
(CET2031B)
Java Programming 1
Lab 5
Problem Statement
Develop a simple web application using the concept of Servlets, JSP, and database
connectivity
Java Programming 2
Objective of the Assignment
Java Programming 3
JSP
JSP technology is used to create web application just like Servlet technology but with
more functionality
A JSP page consists of HTML tags and JSP tags.
Advantages of JSP over Servlet
• Extension to Servlet
• Easy to maintain - we can easily separate our business logic from presentation logic
• Fast Development: No need to recompile and redeploy
• Less code than Servlet
JSP page is translated into Servlet by the help of JSP translator. The JSP translator
is a part of the web server which is responsible for translating the JSP page into
Servlet. After that, Servlet page is compiled by the compiler and gets converted
into the class file.
Java Programming 4
Creating a simple JSP Page
• To create the first JSP page, write some HTML code as given below, and save it by .jsp extension. We have
saved this file as index.jsp. Put it in a folder and paste the folder in the web-apps directory in apache
tomcat to run the JSP page.
<html>
<body>
<% out.print(2*5); %>
</body>
</html>
Java Programming 5
Directory Structure of JSP
The directory structure of JSP page is same as Servlet. We contain the JSP page
outside the WEB-INF folder or in any directory.
Java Programming 6
JSP API
The JSP API consists of two packages:
1. javax.servlet.jsp
2. javax.servlet.jsp.tagext
The javax.servlet.jsp package has two interfaces and classes.The two
interfaces are as follows:
1. JspPage
2. HttpJspPage
Java Programming 7
Creating JSP in Eclipse IDE with Tomcat
server
1. Create the dynamic web project
For creating a dynamic web project click <%@ page language="java" contentType="text/html;
on File Menu -> New -> dynamic web charset=ISO-8859-1"
project -> write your project name e.g. first pageEncoding="ISO-8859-1"%>
-> Finish. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
2. Create the JSP file in eclipse IDE "http://www.w3.org/TR/html4/loose.dtd">
For creating a JSP file, explore the project <html>
by clicking the + icon -> right click on <head>
WebContent -> New -> jsp -> write your <meta http-equiv="Content-Type" content="text/html;
jsp file name e.g. index -> next -> Finish. charset=ISO-8859-1">
After creating JSP file, write the code. <title>JSP - Hello World </title>
</head>
3. Start the tomcat server and deploy <body>
the project <%= "Hello World!" %>
For starting the server and deploying the </body>
project in one step Right click on your </html>
project -> Run As -> Run on Server ->
choose tomcat server -> next -> addAll ->
finish.
Java Programming 8
Thank You!!
Java Programming 9