SlideShare a Scribd company logo
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
Servlet., tomcat server, implicit jsp object
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)

PPTX
WT Unit-Vuufvmjn dissimilating Dunkirk k
asta9578
 
PPTX
JSP overview
Amisha Narsingani
 
PPTX
Java web application development
RitikRathaur
 
PPT
JSP 1.pptdfdfdfdsfdsfdsfdsfdsgdgdgdgdgdd
zmulani8
 
PPT
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
PDF
HTTP, JSP, and AJAX.pdf
Arumugam90
 
PPTX
JAVA SERVER PAGES
Kalpana T
 
PPTX
Core web application development
Bahaa Farouk
 
PPTX
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
PDF
Java part 3
ACCESS Health Digital
 
PPT
3.jsp tutorial
shiva404
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
The java server pages
Atul Saurabh
 
PPT
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
PPTX
Learning jsp
mustafacse2009
 
PPT
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
MasterCode.vn
 
PPTX
JSP.pptx programming guide for beginners and experts
rani marri
 
PPT
Jsp ppt
Vikas Jagtap
 
PPTX
Server side programming
javed ahmed
 
WT Unit-Vuufvmjn dissimilating Dunkirk k
asta9578
 
JSP overview
Amisha Narsingani
 
Java web application development
RitikRathaur
 
JSP 1.pptdfdfdfdsfdsfdsfdsfdsgdgdgdgdgdd
zmulani8
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
HTTP, JSP, and AJAX.pdf
Arumugam90
 
JAVA SERVER PAGES
Kalpana T
 
Core web application development
Bahaa Farouk
 
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
3.jsp tutorial
shiva404
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
The java server pages
Atul Saurabh
 
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
Learning jsp
mustafacse2009
 
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
MasterCode.vn
 
JSP.pptx programming guide for beginners and experts
rani marri
 
Jsp ppt
Vikas Jagtap
 
Server side programming
javed ahmed
 

Recently uploaded (20)

PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
GitOps_Without_K8s_Training simple one without k8s
DanialHabibi2
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Day2 B2 Best.pptx
helenjenefa1
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
MRRS Strength and Durability of Concrete
CivilMythili
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Ad

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
  • 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>