SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
13-05-2013Rajavel DRajavel D
Java Server Pages / Servlets
Summer Internship – 2013
(Indian Institute of Technology Bombay)
Servlets
 Java Servlets are programs that run on a Web or
Application server.
 Middle layer between HTTP client (Browser) and
HTTP server (Web / Application)
 Full functionality of java and includes HTTP request
and response.
 Contain java code and embedded HTML tags
 HTML code is return in PrintWriter.println()
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Servlets Architecture
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Java Server Pages (JSP)
 JSP is dynamic web page
 JSP is written as ordinary HTML, with a little Java
mixed
 The Java is enclosed in special tags, such as
<% ... %>
 JSP files must have the extension .jsp
 JSP is translated into a Java servlet, which is then
compiled
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Environment
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Servlet / JSP Life cycle
 Init
 Called once when servlet / jsp is created
 Service
 Do the service based on request type (get, post … )
 Destroy
 Called only once at the end of the life cycle of a
servlet / jsp.
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Tags
 <%= expression %>
 The expression is evaluated and the result is inserted
into the HTML page
 <% code %>
 The code is inserted into the servlet's service method
 This construction is called a scriptlet
 <%! declarations %>
 The declarations are inserted into the servlet class, not
into a method
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Example JSP Code
 <HTML>
<BODY>
Hello! The time is now <%= new java.util.Date() %>
</BODY>
</HTML>
 Notes:
– The <%= ... %> tag is used, because we are computing a
value and inserting it into the HTML
– The fully qualified name (java.util.Date) is used, instead
of the short name (Date), because we haven’t yet talked
about how to do import declarations
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Scriptlets
 Scriptlets are enclosed in <% ... %> tags
 Scriptlets are Java code that may write into the HTML
 Scriptlets are inserted into the servlet exactly as written
 Example:
<% if (Math.random() < 0.5) { %>
Have a <B>nice</B> day!
<% } else { %>
Have a <B>good</B> day!
<% } %>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Declarations
 Use <%! ... %> tag for declarations
 If declared with <% ... %>, variables are local
 Example:
<%! int accessCount = 0; %>
:
<%= ++accessCount %>
 You can use <%! ... %> to declare methods as easily
as to declare variables
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Comments
 Different from HTML comments.
 HTML comments are visible to client.
 <!-- an HTML comment -->
 JSP comments are used for documenting JSP
code.
 JSP comments are not visible client-side.
 <%-- a JSP comment --%>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Directives
 <%@ page ... %>
 Defines page-dependent attributes, such as scripting
language, error page, and buffering requirements.
 <%@ include ... %>
 Includes a file during the translation phase.
 <%@ taglib ... %>
 Declares a tag library, containing custom actions, used
in the page
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
The page Directive
 <%@ page attribute="value" %>
 Examples
 <%@ page contentType="text/html or text/xml" %>
 <%@ page autoFlush="true" %>
 <%@ page errorPage="MyErrorPage.jsp" %>
 <%@ page import="java.sql.*,java.util.*" %>
 <%@ page info="This JSP Page Written By Raj" %>
 <%@ page session="true" %>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
The include Directive
 <%@ include file="relative url" >
 Examples
 <%@ include file="header.jsp" %>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Action Tags
 Actions are XML-syntax tags used to control the servlet
engine
 <jsp:action_name attribute="value" />
 <jsp:include page="URL " />
 Inserts the relative URL at execution time (not at compile
time, like the include directive does)
 <jsp:forward page="URL" />
<jsp:forward page="www.google.co.in" />
 Forward the page to specified URL
 <jsp: param name="myParam" value="Amar Patel"/>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Default Objects
 request : The HttpServletRequest parameter
 response : The HttpServletResponse parameter
 session : The HttpSession associated with the
request, or null if there is none
 out : A JspWriter (like a PrintWriter) used to
send output to the client
 application : Exist through out the application
 exception : Show the error information
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Implicit Object - Example
 Request :
request.getQueryString();
request.getParameter("name");
request.getRequestURI()
 Response :
response.sendRedirect("http://www.google.co.in”);
response.setHeader("Cache-Control","no-cache");
response.setContentType("text/html");
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Session Object
 In session management whenever a request comes
for any resource, a unique token is generated by
the server and transmitted to the client by the
response object and stored on the client machine
as a cookie.
 Session management
 Session Object
 Cookies
 Hidden Form Fields
 URL Rewriting
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Session Object (cont.)
 Set Session Attribute
session.setAttribute(“myname",name);
 Get Session value
 session.getAttribute(" myname")
 Remove Session Attribute
 session.removeAttribute(" myname")
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
JSP Application Object
<% Integer hitsCount =
(Integer)application.getAttribute("hitCounter");
if( hitsCount ==null || hitsCount == 0 ){
out.println("Welcome to my website!");
HitsCount = 1;
}else{
out.println("Welcome back to my website!");
hitsCount += 1;
} application.setAttribute("hitCounter", hitsCount); %>
<p>Total number of visits: <%= hitsCount%></p>
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Rajavel D JSP/Servlet IITB-CSE-Internship 2013
Any Doubts ???
References
 www.tutorialspoint.com/jsp/index.htm
 www.tutorialspoint.com/servlets/index.htm
 java.sun.com/j2ee/tutorial/1_3-
fcs/doc/JSPIntro.html
 www.roseindia.net/jsp/jsp.htm
 www.jsptutorial.net/
Rajavel D JSP/Servlet IITB-CSE-Internship 2013

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
JDBC
JDBCJDBC
JDBC
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and Containers
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Servlets
ServletsServlets
Servlets
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
JSP
JSPJSP
JSP
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Java servlets
Java servletsJava servlets
Java servlets
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 

Ähnlich wie Jsp servlets (20)

J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Jsp
JspJsp
Jsp
 
Introduction to JSP pages
Introduction to JSP pagesIntroduction to JSP pages
Introduction to JSP pages
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp  - Giáo trình Bách Khoa AptechSession 5 : intro to jsp  - Giáo trình Bách Khoa Aptech
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
 
Jsp
JspJsp
Jsp
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp element
Jsp elementJsp element
Jsp element
 
Jsp & struts
Jsp & strutsJsp & struts
Jsp & struts
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 

Kürzlich hochgeladen

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Kürzlich hochgeladen (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Jsp servlets

  • 1. 13-05-2013Rajavel DRajavel D Java Server Pages / Servlets Summer Internship – 2013 (Indian Institute of Technology Bombay)
  • 2. Servlets  Java Servlets are programs that run on a Web or Application server.  Middle layer between HTTP client (Browser) and HTTP server (Web / Application)  Full functionality of java and includes HTTP request and response.  Contain java code and embedded HTML tags  HTML code is return in PrintWriter.println() Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 3. Servlets Architecture Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 4. Java Server Pages (JSP)  JSP is dynamic web page  JSP is written as ordinary HTML, with a little Java mixed  The Java is enclosed in special tags, such as <% ... %>  JSP files must have the extension .jsp  JSP is translated into a Java servlet, which is then compiled Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 5. JSP Environment Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 6. Servlet / JSP Life cycle  Init  Called once when servlet / jsp is created  Service  Do the service based on request type (get, post … )  Destroy  Called only once at the end of the life cycle of a servlet / jsp. Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 7. JSP Tags  <%= expression %>  The expression is evaluated and the result is inserted into the HTML page  <% code %>  The code is inserted into the servlet's service method  This construction is called a scriptlet  <%! declarations %>  The declarations are inserted into the servlet class, not into a method Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 8. Example JSP Code  <HTML> <BODY> Hello! The time is now <%= new java.util.Date() %> </BODY> </HTML>  Notes: – The <%= ... %> tag is used, because we are computing a value and inserting it into the HTML – The fully qualified name (java.util.Date) is used, instead of the short name (Date), because we haven’t yet talked about how to do import declarations Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 9. Scriptlets  Scriptlets are enclosed in <% ... %> tags  Scriptlets are Java code that may write into the HTML  Scriptlets are inserted into the servlet exactly as written  Example: <% if (Math.random() < 0.5) { %> Have a <B>nice</B> day! <% } else { %> Have a <B>good</B> day! <% } %> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 10. Declarations  Use <%! ... %> tag for declarations  If declared with <% ... %>, variables are local  Example: <%! int accessCount = 0; %> : <%= ++accessCount %>  You can use <%! ... %> to declare methods as easily as to declare variables Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 11. JSP Comments  Different from HTML comments.  HTML comments are visible to client.  <!-- an HTML comment -->  JSP comments are used for documenting JSP code.  JSP comments are not visible client-side.  <%-- a JSP comment --%> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 12. Directives  <%@ page ... %>  Defines page-dependent attributes, such as scripting language, error page, and buffering requirements.  <%@ include ... %>  Includes a file during the translation phase.  <%@ taglib ... %>  Declares a tag library, containing custom actions, used in the page Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 13. The page Directive  <%@ page attribute="value" %>  Examples  <%@ page contentType="text/html or text/xml" %>  <%@ page autoFlush="true" %>  <%@ page errorPage="MyErrorPage.jsp" %>  <%@ page import="java.sql.*,java.util.*" %>  <%@ page info="This JSP Page Written By Raj" %>  <%@ page session="true" %> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 14. The include Directive  <%@ include file="relative url" >  Examples  <%@ include file="header.jsp" %> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 15. Action Tags  Actions are XML-syntax tags used to control the servlet engine  <jsp:action_name attribute="value" />  <jsp:include page="URL " />  Inserts the relative URL at execution time (not at compile time, like the include directive does)  <jsp:forward page="URL" /> <jsp:forward page="www.google.co.in" />  Forward the page to specified URL  <jsp: param name="myParam" value="Amar Patel"/> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 16. JSP Default Objects  request : The HttpServletRequest parameter  response : The HttpServletResponse parameter  session : The HttpSession associated with the request, or null if there is none  out : A JspWriter (like a PrintWriter) used to send output to the client  application : Exist through out the application  exception : Show the error information Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 17. JSP Implicit Object - Example  Request : request.getQueryString(); request.getParameter("name"); request.getRequestURI()  Response : response.sendRedirect("http://www.google.co.in”); response.setHeader("Cache-Control","no-cache"); response.setContentType("text/html"); Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 18. JSP Session Object  In session management whenever a request comes for any resource, a unique token is generated by the server and transmitted to the client by the response object and stored on the client machine as a cookie.  Session management  Session Object  Cookies  Hidden Form Fields  URL Rewriting Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 19. JSP Session Object (cont.)  Set Session Attribute session.setAttribute(“myname",name);  Get Session value  session.getAttribute(" myname")  Remove Session Attribute  session.removeAttribute(" myname") Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 20. JSP Application Object <% Integer hitsCount = (Integer)application.getAttribute("hitCounter"); if( hitsCount ==null || hitsCount == 0 ){ out.println("Welcome to my website!"); HitsCount = 1; }else{ out.println("Welcome back to my website!"); hitsCount += 1; } application.setAttribute("hitCounter", hitsCount); %> <p>Total number of visits: <%= hitsCount%></p> Rajavel D JSP/Servlet IITB-CSE-Internship 2013
  • 21. Rajavel D JSP/Servlet IITB-CSE-Internship 2013 Any Doubts ???
  • 22. References  www.tutorialspoint.com/jsp/index.htm  www.tutorialspoint.com/servlets/index.htm  java.sun.com/j2ee/tutorial/1_3- fcs/doc/JSPIntro.html  www.roseindia.net/jsp/jsp.htm  www.jsptutorial.net/ Rajavel D JSP/Servlet IITB-CSE-Internship 2013