SlideShare a Scribd company logo
4
Most read
10
Most read
15
Most read
C603.1 Design GUI using AWT and Swing .
C603.2 Develop program using event handling.
C603.3 Use network concepts (client/server, socket) in the
program.
C603.4 Develop program using JDBC connectivity to access data
from database and execute different queries to get
required result.
C603.5 Develop web based program using servlet and JSP
Course Outcomes of
Advanced Java Programming AJP (17625, C603)
Visit for more Learning Resources
Java Servlets and JSP
Server-side Java for the web
 a servlet is a Java program which outputs an html
page; it is a server-side technology
browser
web server
HTTP Request
HTTP Response
Server-side Request
Response Header +
Html file
Java Servlet
Java Server Page
servlet container
(engine) - Tomcat
First java servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>First servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("It works...<hr>");
out.println("</body>");
out.println("</html>");
}
}
What is a java servlet ?
 a java servlet is a java class extending HTTPServlet
class
 a java servlet class implements the doGet(), doPost()
or other equivalent HTTP method and (usually) prints
at the standard output an html file
 a java servlet class can contain any kind of java code
the JDK can compile
 a java servlet class needs to be compiled prior to using
it; it must use servlet-api.jar
Apache Tomcat
 the most well known servlet/jsp container
 is a web server + implementation of Java Servlet and
JSP (Java Server Pages) APIs
 is developed by Apache Software Foundation
 available at http://tomcat.apache.org/ under Apache
Software License
Installing Tomcat
1. Download the binary zip distribution (e.g. apache-
tomcat-6.0.20.zip) in a local folder (we will use c:temp
in the rest of the guide)
2. Set the environment variables
JAVA_HOME=path_to_JDK_installation_folder
CATALINA_HOME=path_to_tomcat_installation_folder
either as Windows system variables or in the files
startup.bat and shutdown.bat from the bin directory
Ex. place the following lines in the beginning of startup.bat
and shutdown.bat:
set JAVA_HOME=c:progra~1javajdk1.6.0
set CATALINA_HOME=c:tempapache-tomcat-6.0.20
Starting/shutting down Tomcat
 start Tomcat from a cmd prompter (window):
c:tempapache-tomcat-6.0.20binstartup.bat
 verify startup by pointing a browser to the url
http://localhost:8080
 shutting down Tomcat from a cmd prompter
(window):
c:tempapache-tomcat-6.0.20binshutdown.bat
Tomcat standard folders
 bin – contains executable files for controlling the server
(start, shut down etc.)
 conf – contains configuration files; most important
server.xml for configuring the server and web.xml a
general configuration file for web applications
 lib – libraries (jars) used by tomcat and deployed web
applications
 logs – log files
 temp – temporary files
 webapps – contains the web applications deployed
 work – contains files created by tomcat during running
(e.g. it crates a servlet from each jsp file)
Format of a web application
 web applications are stored in the webapps folder,
either as a folder or as a .war archive
 a web application (either a folder or a .war archive)
must contain the following files:
 WEB-INF folder
 WEB-INFweb.xml: a configuration file
 optionally the WEB-INF folder can contain the following
subfolders:
 classes: which contain servlets
 lib: which contains jars used by the web application
 html, jsp and resource files can be placed anywhere in
the web application home folder
 servlets must be placed in the folder or subfolders of
WEB-INFclasses
A very simple web.xml example
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd version="2.5">
</web-app>
Configuring servlets
 for JSPs (Java Server Pages) no additional
configuration needs to be done
 for java servlets additional lines must be placed in the
web.xml file:
<servlet>
<servlet-name>ServletsName</servlet-name>
<servlet-class>The_Class_Name_of_the_Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> ServletsName </servlet-name>
<url-pattern>/URL_of_the_servlet</url-pattern>
</servlet-mapping>
First JSP file
<html>
<body>
<%
out.println(“First JSP… It works<br/>");
%>
</body>
</html>
What is a Java Server Page (JSP)
 an html file containing parts of java code; the java code
is placed inside the “<% … %>” tags or some other
related tags
 Tomcat will create a servlet from the jsp file (which will
be saved in the work folder)
 when the jsp is requested the servlet is executed and
the output of the server is sent back to the client
Additional documentation
 for Servlets:
http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/07JavaServlet.pdf
 for JSP:
http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/08JavaServerPages.pdf
 examples of both:
http://www.cs.ubbcluj.ro/~forest/wp/JSP%20Servlet%20examples
For more detail contact us

More Related Content

DOC
Java Servlets & JSP
PPT
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
DOC
Unit5 servlets
PPT
1 java servlets and jsp
PPTX
PPTX
Chapter 3 servlet & jsp
PPTX
Cis 274 intro
PDF
01 overview-and-setup
Java Servlets & JSP
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
Unit5 servlets
1 java servlets and jsp
Chapter 3 servlet & jsp
Cis 274 intro
01 overview-and-setup

Similar to Introduction to Java Servlets and JSP (1).ppt (20)

PPTX
BITM3730Week12.pptx
PPT
Java Servlets
PPTX
WEB TECHNOLOGY Unit-3.pptx
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
PDF
Jsp tutorial
PPTX
Server side programming
PPTX
Web container and Apache Tomcat
PPTX
Jsp and Servlets
PPT
Updated-Servlet Introduction Lifecycle of Servlet
PPTX
Advance Java Topics (J2EE)
PPT
Presentation on java servlets
PPT
Ppt for Online music store
PPTX
Http Server Programming in JAVA - Handling http requests and responses
PPTX
Core web application development
PPT
JAVA Servlets
PPT
Java EE 02-First Servlet
PDF
PDF
PPT
Web Application Deployment
PPTX
AJppt.pptx
BITM3730Week12.pptx
Java Servlets
WEB TECHNOLOGY Unit-3.pptx
SERVLETS (2).pptxintroduction to servlet with all servlets
Jsp tutorial
Server side programming
Web container and Apache Tomcat
Jsp and Servlets
Updated-Servlet Introduction Lifecycle of Servlet
Advance Java Topics (J2EE)
Presentation on java servlets
Ppt for Online music store
Http Server Programming in JAVA - Handling http requests and responses
Core web application development
JAVA Servlets
Java EE 02-First Servlet
Web Application Deployment
AJppt.pptx
Ad

More from ansariparveen06 (20)

PPT
Preprocessing of data mining process.ppt
PPT
8. Ozone and Environmental issue and solution.ppt
PPTX
ALP intro assembly language programing.pptx
PPT
cpphtp9_Exception handling in c++ .ppt
PPT
introduction to javascript concepts .ppt
PPT
java multi threading and synchronisation.ppt
PPTX
Environmental studies part2 bscit sem2.pptx
PPTX
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
PPT
exception-handling-in-java programming.ppt
PPTX
brief introduction to core java programming.pptx
PPTX
Module1 evs Environmental Pollution.pptx
PPTX
Internet_Banking e commerce in banking.pptx
PPTX
UNIT1 Decision Support System in BI.pptx
PPT
logic gate based on discrete mathematics.ppt
PPTX
Overview on how to Disciplining in life .pptx
PPT
presentation on java server pages vs servlet.ppt
PPTX
enterprise java - introduction to servlet.pptx
PPTX
Introduction to Operating - Systems.pptx
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
Preprocessing of data mining process.ppt
8. Ozone and Environmental issue and solution.ppt
ALP intro assembly language programing.pptx
cpphtp9_Exception handling in c++ .ppt
introduction to javascript concepts .ppt
java multi threading and synchronisation.ppt
Environmental studies part2 bscit sem2.pptx
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
exception-handling-in-java programming.ppt
brief introduction to core java programming.pptx
Module1 evs Environmental Pollution.pptx
Internet_Banking e commerce in banking.pptx
UNIT1 Decision Support System in BI.pptx
logic gate based on discrete mathematics.ppt
Overview on how to Disciplining in life .pptx
presentation on java server pages vs servlet.ppt
enterprise java - introduction to servlet.pptx
Introduction to Operating - Systems.pptx
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
Ad

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Institutional Correction lecture only . . .
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Types and Its function , kingdom of life
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Lesson notes of climatology university.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Basic Mud Logging Guide for educational purpose
master seminar digital applications in india
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
RMMM.pdf make it easy to upload and study
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Module 4: Burden of Disease Tutorial Slides S2 2025
Renaissance Architecture: A Journey from Faith to Humanism
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
VCE English Exam - Section C Student Revision Booklet
Institutional Correction lecture only . . .
O7-L3 Supply Chain Operations - ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Types and Its function , kingdom of life
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial disease of the cardiovascular and lymphatic systems
Lesson notes of climatology university.
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Basic Mud Logging Guide for educational purpose

Introduction to Java Servlets and JSP (1).ppt

  • 1. C603.1 Design GUI using AWT and Swing . C603.2 Develop program using event handling. C603.3 Use network concepts (client/server, socket) in the program. C603.4 Develop program using JDBC connectivity to access data from database and execute different queries to get required result. C603.5 Develop web based program using servlet and JSP Course Outcomes of Advanced Java Programming AJP (17625, C603) Visit for more Learning Resources
  • 3. Server-side Java for the web  a servlet is a Java program which outputs an html page; it is a server-side technology browser web server HTTP Request HTTP Response Server-side Request Response Header + Html file Java Servlet Java Server Page servlet container (engine) - Tomcat
  • 4. First java servlet import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class FirstServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>First servlet</title>"); out.println("</head>"); out.println("<body>"); out.println("It works...<hr>"); out.println("</body>"); out.println("</html>"); } }
  • 5. What is a java servlet ?  a java servlet is a java class extending HTTPServlet class  a java servlet class implements the doGet(), doPost() or other equivalent HTTP method and (usually) prints at the standard output an html file  a java servlet class can contain any kind of java code the JDK can compile  a java servlet class needs to be compiled prior to using it; it must use servlet-api.jar
  • 6. Apache Tomcat  the most well known servlet/jsp container  is a web server + implementation of Java Servlet and JSP (Java Server Pages) APIs  is developed by Apache Software Foundation  available at http://tomcat.apache.org/ under Apache Software License
  • 7. Installing Tomcat 1. Download the binary zip distribution (e.g. apache- tomcat-6.0.20.zip) in a local folder (we will use c:temp in the rest of the guide) 2. Set the environment variables JAVA_HOME=path_to_JDK_installation_folder CATALINA_HOME=path_to_tomcat_installation_folder either as Windows system variables or in the files startup.bat and shutdown.bat from the bin directory Ex. place the following lines in the beginning of startup.bat and shutdown.bat: set JAVA_HOME=c:progra~1javajdk1.6.0 set CATALINA_HOME=c:tempapache-tomcat-6.0.20
  • 8. Starting/shutting down Tomcat  start Tomcat from a cmd prompter (window): c:tempapache-tomcat-6.0.20binstartup.bat  verify startup by pointing a browser to the url http://localhost:8080  shutting down Tomcat from a cmd prompter (window): c:tempapache-tomcat-6.0.20binshutdown.bat
  • 9. Tomcat standard folders  bin – contains executable files for controlling the server (start, shut down etc.)  conf – contains configuration files; most important server.xml for configuring the server and web.xml a general configuration file for web applications  lib – libraries (jars) used by tomcat and deployed web applications  logs – log files  temp – temporary files  webapps – contains the web applications deployed  work – contains files created by tomcat during running (e.g. it crates a servlet from each jsp file)
  • 10. Format of a web application  web applications are stored in the webapps folder, either as a folder or as a .war archive  a web application (either a folder or a .war archive) must contain the following files:  WEB-INF folder  WEB-INFweb.xml: a configuration file  optionally the WEB-INF folder can contain the following subfolders:  classes: which contain servlets  lib: which contains jars used by the web application  html, jsp and resource files can be placed anywhere in the web application home folder  servlets must be placed in the folder or subfolders of WEB-INFclasses
  • 11. A very simple web.xml example <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd version="2.5"> </web-app>
  • 12. Configuring servlets  for JSPs (Java Server Pages) no additional configuration needs to be done  for java servlets additional lines must be placed in the web.xml file: <servlet> <servlet-name>ServletsName</servlet-name> <servlet-class>The_Class_Name_of_the_Servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name> ServletsName </servlet-name> <url-pattern>/URL_of_the_servlet</url-pattern> </servlet-mapping>
  • 13. First JSP file <html> <body> <% out.println(“First JSP… It works<br/>"); %> </body> </html>
  • 14. What is a Java Server Page (JSP)  an html file containing parts of java code; the java code is placed inside the “<% … %>” tags or some other related tags  Tomcat will create a servlet from the jsp file (which will be saved in the work folder)  when the jsp is requested the servlet is executed and the output of the server is sent back to the client
  • 15. Additional documentation  for Servlets: http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/07JavaServlet.pdf  for JSP: http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/08JavaServerPages.pdf  examples of both: http://www.cs.ubbcluj.ro/~forest/wp/JSP%20Servlet%20examples For more detail contact us