SlideShare a Scribd company logo
1 of 40
Download to read offline
Topics to be covered...
Y-rvlet
yervlet life cycle
J;ommon Gateway Interface (CGI)
Cookies
Java Server Page (JSP)
JSP Important tags
JSP Architecture
Tomcat Server
Implicit objects available in JSP
Standard actions in JSP
JSP Directives
Happy Ending!
--
1234567
ro
Servlet
Servlet
,.Y'Servlets are the Java programs that run on the Java-enabled web server.
• They are used to handle the request obtained from the webserver, process the request,
produce the response, then send a response back to the webserver.
• Servlet also called servlet.
• Used in the cookies and session tracking.
,,,,,,,,,_{!l1
-·-
t---,0 ----
11
HTTP Server Servlet Pr0&ram o.-tabue
Servlet life cycle
J' init()
/service()
~ estroy()
Initialization
init()
Service Destruction
service() destroy()
Request/Response
Servlet life cycle
-i· ~ )
~ • The init() method is called only once.
• It is called only when the servlet is created, and not called for any user requests afterwards.
• It is used for one-time initializations, just as with the init () method of applets.
• The init() method must complete successfully before the servlet can receive any requests.
public void init() throws ServletException {
I I Initialization code . ..
Servlet life cycle
'2_ ·S~e(}
~0he service() method is called only after the init() method.
• It is the main method to perform the actual task.
• The servlet container calls the service() method to handle requests coming from the client.
• The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.)
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
Servlet life cycle
~ troy()
y The destroy() method is called only once at the end of the life cycle of a servlet.
• It gives your servlet a chance to close database connections.
• After the destroy() method is called, the servlet object is marked for garbage collection.
public void destroy() {
// Finalization code . . .
S9111mon Gateway Interface (CGI)
~ GI is a standard way for a Web server to pass a Web user's request to an application
program and to receive data back to forward to the user.
• CGI used to provide dynamic content to the user.
• The World Wide Web Consortium (W3C) defined the Common Gateway Interface (CGI)
and also defined how a program interacts with a Hyper Text Transfer Protocol (HTTP)
server.
'Web Browser
HTTP HTTP
Request Results
Server .-----.i ~ GI Program
Java servlets advantages over C~
,jPlatform independence: Java servlet are pure Java program and it can run on any servlet
enabled web server. ~ ~ ½ ~ J,~
/ Safety: Memory manag ~. e~ on handling. ...--
~ ecure: Servlets are server side components, so it inherit the security provided by the web
server.
/ Performance
y xtensibility
89%
Cookies
• Cookies are small files which are stored on a user's computer.
• When you select your language in which you want to view your website, the website would
save the information in a document called a cookie on your computer, and the next time
when you visit the website, it would be able to read a cookie saved earlier. That way the
website could remember your language and let you view the website in your preferred
language without having to select the language again.
• A cookie can contain any type of information such as the time when you visited the website,
the items that you added into your shopping basket, all the links you clicked in website, etc.,
Cookies
Typ~s of Cook·es.
Vsession Cookies - These are mainly used by online shops and allows you to keep items in
your basket when shopping online. These cookies expire after a specific time or when the
browser is closed.
• Permanent Cookies - These remain in operation, even when you have closed the browser.
They remember your login details and password so you don't have to type them in every
time you use the site. It is recommended that you delete these type of cookies after a
specific time.
• Third-Party Cookies - These are installed by third parties for collecting certain information.
For example: Google Maps.
WWW,
WWW
~ Server Page (J§_el
CIX1 ►~50
vl)J _; V
I L---
~ JSP technology is used to create web application just like Servlet technology. . u11{n-,;-~
y supports both Sf.dmjng and element based dynamic content and allow developers to ~
create their own tag libraries ~
• A JSP page consists of HTML tags and JSP tags. ~ ,.,
• JSP tags are reusable. So, the pages run faster.
• Java Server Pages often serve the same purpose as programs implemented using the
Common Gateway Interface (CGI). But JSP offers several advantages in comparison with
the CGI.
OB
JSP Request Web Server
HTML page
Client
U
SP. lmregoffl:arntti
il:ags
i• Declarative Tag
--:;::::::::--
' "'~ °'- -=-~~
1;.,, )-, j
<C../( .
JCl,~
~
·/·>
v~•C 'i'vi.- ~~ (_), {
~E})
3
-/ >
t::. ./. I
I
Script Tag
i111 ~--s ~
i '--'d IJ ;L'·/
 L ,;.
o<d<-~o'Md).11 l~L) );,
Expression Tag
LtJ 5A~ l't>', L.'I•-=- 5<,'M() ·I·> C(.lt,1)
.._/""
JSP Architecture
~ p architecture is a 3 tier architecture.v
.Y'fhe client is the web browser or application on the user side.
• It is a server-side technology for creating web applications.
~ tags are used to insert JAVA code into HTML pages.
• It i~ dvanced version of Servlet Technology.
• ~ dynamic and platform-independent web pages.
---OB
JSP Request WebSel'Vff ~
~HTMLpa~°' ~
Client
JSP Architecture
• Step1: Client navigates to a file the ,.j~P- extension and the browser initiates an HTTP
request to the webserver.
• Step2: If the compiled version of JSP exists in the web server, it returns the file. Otherwise,
the request is forwarded to the JSP Engine.
• Step 3: The JSP Engine loads the JSP file and translates the JSP to Servlet(Java code). This
process is called translation.
• Step4: The JSP engine compiles the Servlet to an executable .class file. It is forwarded to
the Servlet engine. This process is called compilation phase.
• Step 5: The .class file is executed by the Servlet engine which is a part of the Web Server.
The output is an HTML file. The Servlet engine passes the output as an HTTP response to
the webserver.
• Step 6: The web server forwards the HTML file to the client's browser.
JSP Architecture
Jlfltml>
<pody>
~ ction='~ e
~ omej sp''>
~ u~ ~ '>
~ ut type="s~ it" value="~ '><br/>
</form>
</body>
</html>
~'.~
""~- /
~
G Sc/4f/J-?J)-
<htmlc:.,.,,-- ___.:.--
<body>/
a g na~ =request.getParameter("pname");
out.priot('~ elcome "+name); '
%>
</form>
</body>
</html> /J
~ .-"] 5i;r
10:25 ,&i M ,,11 84%
Tomcat Server
(J,is an open-source Java servlet container that implements many Java Enterprise Specs
such as the Websites API, Java-Server Pages and last but not least, the Java Servlet.
• Complete name of Tomcat is "Apache Tomcat".
• Static website- HTTP server
• Dynamic website- servlet
• HTTP server + servlet = become a single server know as tomcat server.
• We can say servlet container
□~~~
ltfill§p
84%
Implicit objects available in JSP
._yfl,ere are 9 jsp implicit objects.
~ese objects are created by the ~ hat are available to all the jsp pages.
Objtrr Typt>
out JspWnter
request HttpServletRequest
response HnpServletResponse
config ServletConfig
application ServletContext
session HttpSession
pageContext PageContext
page Object
exception Throwable
Implicit objects available in JSP
1) JSP out object:
• For writing any data to the buffer.
• It is the object of JspWriter.
• In case of servlet you need to write: PrintWriter out=response.getWriter();
l.<html>
2.<body>
3.<% out.print("Today is:"+java.util.Calendar.getlnstance().getTime()); % >
4.</body>
5.</html>
Implicit objects available in JSP
~p request object:
• Type: HttpServletRequest
• It can be used to get request information such as parameter, header information, server
name, server port, content type etc.
• It can also be used to set, get and remove attributes from the jsp request scope.
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
<%
String name=request.getParameter("uname");
out.print("welcome "+name);
%>
Implicit objects available in JSP
3) JSP Is'~ Qbject:
• Type: HttpServletResponse
4) JSP config object:
<%
response.sendRedirect("http://www.google.com");
%>
• Type: type ServletConfig
• It is used to get initialization parameter from the w eb.xml file.
<%
out.print("Welcome "+request.getParameter(''uname"));
String driver=config.getlnitParameter("dname");
out.print("driver name is="+driver);
%>
Implicit objects available in JSP
5) JSP application object:
• Type: ServletContext.
• The instance of ServletContext is created only once by the web container when project is
deployed on the server.
• This initialization parameter can be used by all jsp pages.
6) JSP session object:
• Type: HttpSession
• The Java developer can use this object to set.get or remove attribute or to get session
information.
7) JSP pageContext object:
• Type: PageContext class.
• The pageContext object can be used to set.get or remove attribute from one of the
following scopes: page, request, session, application.
Implicit objects available in JSP
8) J~P page object:
J Type: Object class.
• This object is assigned to the reference of auto generated servlet class.
1 9) JSP exception object:
V. Type: java.lang.Throwable class
• This object can be used to print the exception.
• But it can only be used in error pages.
<%@ page isErrorPage=" .ru " %>
<html>
<body>
Sorry following exception occured:<%= exception %>
</body>
</html>
~~
firu ~
Standard actions in JSP
There are ~ Standard Action Tags in JSP.
• jsp:useBean
• jsp:include
• jsp:setProperty
• jsp:getProperty
• jsp:forward
• jsp:plugin
• jsp:attribute
• jsp:body
• jsp:text
• jsp:param
• jsp:attribute
• jsp:output
Standard actions in JSP
jsp:useBea.n----
• This action name is used when we want to use beans in the JSP page.
• With this tag, we can easily invoke a bean.
.JSp.useBean 1d 1111
class="" />
jsp:include
• It also used to insert a jsp file into another file, just like including Directives.
• It is added during request processing phase
jsp:include page="page URL" flush=''true/false">
jsp:setProperty
• This property of standard actions in JSP is used to set the property of the bean.
• We need to define a bean before setting the property
Standard actions in JSP
jsp:getPro~
• This property is used to get the property of the bean.
• It converts into a string and finally inserts into the output.
jsp:fo~
• It is used to forward the request to another jsp or any static page.
• Here the request can be forwarded with no parameters or with parameters.
jsp:plugiv
• It is used to introduce Java components into jsp, i.e., the java components can be either an
applet or bean.
• It detects the browser and adds <object> or <embed> JSP tags into the file
JSP Directives
The jsp directives are messages that tells the web container how to translate a JSP page into
the corresponding servlet.
There are three types of directives:
• page directive
• include directive
• taglib directive
<%@ directive attribute="value" %>
JSP Directives
_!,ASP page directive
•__J]:i-epage directive defines attributes that apply to an entire JSP page.
• Syntax of JSP page directive:
<%@ page attribute="value" %>
Attributes of JSP page directive
• import, contentType, extends, info, buffer, language, isELlgnored, isThreadSafe, autoFlush,
session, pageEncoding, errorPage, isErrorPage
JSP Directives
l)import
• Used to import class, interface or all the members of a package.
• Example of import attribute
<html>
<body>
<%@ page import="java.util.Date" %>
Today is:<%= new Date()%>
</body>
</html>
JSP Directives
~ include directive
• Used to include the contents of any resource it may be jsp file, html file or text file.
• Advantage: Code Reusability
<html>
<body>
<%@ include file="resourceName" %>
<%@ include file="header.html" %>
</body>
</html>
JSP Directives
3. JSP taglib dfu!cti-te
• Whenwewant to use other tag library in our JSP page. Such as JSTL or custom library.
-----
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="E" %>
<html>
<body>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="E" %>
<E:set var= "name" value = "Hello EIOV"></E:set>
<E:out value= "${name}"></E:out>
</body>
</html>

More Related Content

Similar to Servlet., tomcat server, implicit jsp object (20)

Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Ecom 1
Ecom 1Ecom 1
Ecom 1
 
01 overview-and-setup
01 overview-and-setup01 overview-and-setup
01 overview-and-setup
 
Servlets
ServletsServlets
Servlets
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet Technology
 
Jsp
JspJsp
Jsp
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
WEB TECHNOLOGIES JSP
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
11 page-directive
11 page-directive11 page-directive
11 page-directive
 

Recently uploaded

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 

Recently uploaded (20)

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 

Servlet., tomcat server, implicit jsp object

  • 1. Topics to be covered... Y-rvlet yervlet life cycle J;ommon Gateway Interface (CGI) Cookies Java Server Page (JSP) JSP Important tags JSP Architecture Tomcat Server Implicit objects available in JSP Standard actions in JSP JSP Directives Happy Ending! -- 1234567 ro
  • 3. Servlet ,.Y'Servlets are the Java programs that run on the Java-enabled web server. • They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver. • Servlet also called servlet. • Used in the cookies and session tracking. ,,,,,,,,,_{!l1 -·- t---,0 ---- 11 HTTP Server Servlet Pr0&ram o.-tabue
  • 4. Servlet life cycle J' init() /service() ~ estroy() Initialization init() Service Destruction service() destroy() Request/Response
  • 5. Servlet life cycle -i· ~ ) ~ • The init() method is called only once. • It is called only when the servlet is created, and not called for any user requests afterwards. • It is used for one-time initializations, just as with the init () method of applets. • The init() method must complete successfully before the servlet can receive any requests. public void init() throws ServletException { I I Initialization code . ..
  • 6. Servlet life cycle '2_ ·S~e(} ~0he service() method is called only after the init() method. • It is the main method to perform the actual task. • The servlet container calls the service() method to handle requests coming from the client. • The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
  • 7. Servlet life cycle ~ troy() y The destroy() method is called only once at the end of the life cycle of a servlet. • It gives your servlet a chance to close database connections. • After the destroy() method is called, the servlet object is marked for garbage collection. public void destroy() { // Finalization code . . .
  • 8. S9111mon Gateway Interface (CGI) ~ GI is a standard way for a Web server to pass a Web user's request to an application program and to receive data back to forward to the user. • CGI used to provide dynamic content to the user. • The World Wide Web Consortium (W3C) defined the Common Gateway Interface (CGI) and also defined how a program interacts with a Hyper Text Transfer Protocol (HTTP) server. 'Web Browser HTTP HTTP Request Results Server .-----.i ~ GI Program
  • 9. Java servlets advantages over C~ ,jPlatform independence: Java servlet are pure Java program and it can run on any servlet enabled web server. ~ ~ ½ ~ J,~ / Safety: Memory manag ~. e~ on handling. ...-- ~ ecure: Servlets are server side components, so it inherit the security provided by the web server. / Performance y xtensibility
  • 10. 89%
  • 11. Cookies • Cookies are small files which are stored on a user's computer. • When you select your language in which you want to view your website, the website would save the information in a document called a cookie on your computer, and the next time when you visit the website, it would be able to read a cookie saved earlier. That way the website could remember your language and let you view the website in your preferred language without having to select the language again. • A cookie can contain any type of information such as the time when you visited the website, the items that you added into your shopping basket, all the links you clicked in website, etc.,
  • 12. Cookies Typ~s of Cook·es. Vsession Cookies - These are mainly used by online shops and allows you to keep items in your basket when shopping online. These cookies expire after a specific time or when the browser is closed. • Permanent Cookies - These remain in operation, even when you have closed the browser. They remember your login details and password so you don't have to type them in every time you use the site. It is recommended that you delete these type of cookies after a specific time. • Third-Party Cookies - These are installed by third parties for collecting certain information. For example: Google Maps.
  • 14. ~ Server Page (J§_el CIX1 ►~50 vl)J _; V I L--- ~ JSP technology is used to create web application just like Servlet technology. . u11{n-,;-~ y supports both Sf.dmjng and element based dynamic content and allow developers to ~ create their own tag libraries ~ • A JSP page consists of HTML tags and JSP tags. ~ ,., • JSP tags are reusable. So, the pages run faster. • Java Server Pages often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But JSP offers several advantages in comparison with the CGI. OB JSP Request Web Server HTML page Client
  • 16. i• Declarative Tag --:;::::::::-- ' "'~ °'- -=-~~ 1;.,, )-, j <C../( . JCl,~ ~ ·/·> v~•C 'i'vi.- ~~ (_), { ~E}) 3 -/ >
  • 17. t::. ./. I I Script Tag i111 ~--s ~ i '--'d IJ ;L'·/ L ,;. o<d<-~o'Md).11 l~L) );,
  • 18. Expression Tag LtJ 5A~ l't>', L.'I•-=- 5<,'M() ·I·> C(.lt,1) .._/""
  • 19. JSP Architecture ~ p architecture is a 3 tier architecture.v .Y'fhe client is the web browser or application on the user side. • It is a server-side technology for creating web applications. ~ tags are used to insert JAVA code into HTML pages. • It i~ dvanced version of Servlet Technology. • ~ dynamic and platform-independent web pages. ---OB JSP Request WebSel'Vff ~ ~HTMLpa~°' ~ Client
  • 20. JSP Architecture • Step1: Client navigates to a file the ,.j~P- extension and the browser initiates an HTTP request to the webserver. • Step2: If the compiled version of JSP exists in the web server, it returns the file. Otherwise, the request is forwarded to the JSP Engine. • Step 3: The JSP Engine loads the JSP file and translates the JSP to Servlet(Java code). This process is called translation. • Step4: The JSP engine compiles the Servlet to an executable .class file. It is forwarded to the Servlet engine. This process is called compilation phase. • Step 5: The .class file is executed by the Servlet engine which is a part of the Web Server. The output is an HTML file. The Servlet engine passes the output as an HTTP response to the webserver. • Step 6: The web server forwards the HTML file to the client's browser.
  • 21. JSP Architecture Jlfltml> <pody> ~ ction='~ e ~ omej sp''> ~ u~ ~ '> ~ ut type="s~ it" value="~ '><br/> </form> </body> </html> ~'.~ ""~- / ~ G Sc/4f/J-?J)- <htmlc:.,.,,-- ___.:.-- <body>/ a g na~ =request.getParameter("pname"); out.priot('~ elcome "+name); ' %> </form> </body> </html> /J ~ .-"] 5i;r
  • 22. 10:25 ,&i M ,,11 84%
  • 23. Tomcat Server (J,is an open-source Java servlet container that implements many Java Enterprise Specs such as the Websites API, Java-Server Pages and last but not least, the Java Servlet. • Complete name of Tomcat is "Apache Tomcat". • Static website- HTTP server • Dynamic website- servlet • HTTP server + servlet = become a single server know as tomcat server. • We can say servlet container
  • 25. Implicit objects available in JSP ._yfl,ere are 9 jsp implicit objects. ~ese objects are created by the ~ hat are available to all the jsp pages. Objtrr Typt> out JspWnter request HttpServletRequest response HnpServletResponse config ServletConfig application ServletContext session HttpSession pageContext PageContext page Object exception Throwable
  • 26. Implicit objects available in JSP 1) JSP out object: • For writing any data to the buffer. • It is the object of JspWriter. • In case of servlet you need to write: PrintWriter out=response.getWriter(); l.<html> 2.<body> 3.<% out.print("Today is:"+java.util.Calendar.getlnstance().getTime()); % > 4.</body> 5.</html>
  • 27. Implicit objects available in JSP ~p request object: • Type: HttpServletRequest • It can be used to get request information such as parameter, header information, server name, server port, content type etc. • It can also be used to set, get and remove attributes from the jsp request scope. <form action="welcome.jsp"> <input type="text" name="uname"> <input type="submit" value="go"><br/> </form> <% String name=request.getParameter("uname"); out.print("welcome "+name); %>
  • 28. Implicit objects available in JSP 3) JSP Is'~ Qbject: • Type: HttpServletResponse 4) JSP config object: <% response.sendRedirect("http://www.google.com"); %> • Type: type ServletConfig • It is used to get initialization parameter from the w eb.xml file. <% out.print("Welcome "+request.getParameter(''uname")); String driver=config.getlnitParameter("dname"); out.print("driver name is="+driver); %>
  • 29. Implicit objects available in JSP 5) JSP application object: • Type: ServletContext. • The instance of ServletContext is created only once by the web container when project is deployed on the server. • This initialization parameter can be used by all jsp pages. 6) JSP session object: • Type: HttpSession • The Java developer can use this object to set.get or remove attribute or to get session information. 7) JSP pageContext object: • Type: PageContext class. • The pageContext object can be used to set.get or remove attribute from one of the following scopes: page, request, session, application.
  • 30. Implicit objects available in JSP 8) J~P page object: J Type: Object class. • This object is assigned to the reference of auto generated servlet class. 1 9) JSP exception object: V. Type: java.lang.Throwable class • This object can be used to print the exception. • But it can only be used in error pages. <%@ page isErrorPage=" .ru " %> <html> <body> Sorry following exception occured:<%= exception %> </body> </html>
  • 32. Standard actions in JSP There are ~ Standard Action Tags in JSP. • jsp:useBean • jsp:include • jsp:setProperty • jsp:getProperty • jsp:forward • jsp:plugin • jsp:attribute • jsp:body • jsp:text • jsp:param • jsp:attribute • jsp:output
  • 33. Standard actions in JSP jsp:useBea.n---- • This action name is used when we want to use beans in the JSP page. • With this tag, we can easily invoke a bean. .JSp.useBean 1d 1111 class="" /> jsp:include • It also used to insert a jsp file into another file, just like including Directives. • It is added during request processing phase jsp:include page="page URL" flush=''true/false"> jsp:setProperty • This property of standard actions in JSP is used to set the property of the bean. • We need to define a bean before setting the property
  • 34. Standard actions in JSP jsp:getPro~ • This property is used to get the property of the bean. • It converts into a string and finally inserts into the output. jsp:fo~ • It is used to forward the request to another jsp or any static page. • Here the request can be forwarded with no parameters or with parameters. jsp:plugiv • It is used to introduce Java components into jsp, i.e., the java components can be either an applet or bean. • It detects the browser and adds <object> or <embed> JSP tags into the file
  • 35.
  • 36. JSP Directives The jsp directives are messages that tells the web container how to translate a JSP page into the corresponding servlet. There are three types of directives: • page directive • include directive • taglib directive <%@ directive attribute="value" %>
  • 37. JSP Directives _!,ASP page directive •__J]:i-epage directive defines attributes that apply to an entire JSP page. • Syntax of JSP page directive: <%@ page attribute="value" %> Attributes of JSP page directive • import, contentType, extends, info, buffer, language, isELlgnored, isThreadSafe, autoFlush, session, pageEncoding, errorPage, isErrorPage
  • 38. JSP Directives l)import • Used to import class, interface or all the members of a package. • Example of import attribute <html> <body> <%@ page import="java.util.Date" %> Today is:<%= new Date()%> </body> </html>
  • 39. JSP Directives ~ include directive • Used to include the contents of any resource it may be jsp file, html file or text file. • Advantage: Code Reusability <html> <body> <%@ include file="resourceName" %> <%@ include file="header.html" %> </body> </html>
  • 40. JSP Directives 3. JSP taglib dfu!cti-te • Whenwewant to use other tag library in our JSP page. Such as JSTL or custom library. ----- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="E" %> <html> <body> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="E" %> <E:set var= "name" value = "Hello EIOV"></E:set> <E:out value= "${name}"></E:out> </body> </html>