SlideShare a Scribd company logo
1 of 19
Download to read offline
Java Server Pages


      Summer Internship – 2012
(Indian Institute of Technology Bombay)



                                       Rajavel D
                              (Clicker Software)
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



    IITB                                        - JSP
JSP Environment




IITB                     - JSP
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



    IITB                                                - JSP
Example JSP
 • <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


     IITB                                                  - JSP
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!
     <% } %>




   IITB                                                    - JSP
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




     IITB                                               - JSP
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 --%>



    IITB                                    - JSP
Directives
• Directives affect the servlet class itself

• A directive has the form:
     <%@ directive attribute="value" %>

• The most useful directive is page, which lets you import
  packages
   – Example: <%@ page import="java.util.*" %>




   IITB                                                 - JSP
The include directive

• The include directive inserts another file into the file being
  parsed
• Syntax: <%@ include file="URL " %>
   – The URL is treated as relative to the JSP page
   – If the URL begins with a slash, it is treated as relative to the
     home directory of the Web server
• Example :
   <%@include file="/jsp/header.jsp"%>




     IITB                                                    - JSP
Actions tags
• Actions are XML-syntax tags used to control the servlet engine

• <jsp:include page="URL " />
   – Inserts the relative URL at execution time (not at compile
     time, like the include directive does)
   – This is great for rapidly changing data

• <jsp:forward page="URL" />
  <jsp:forward page="www.google.co.in" />
   – Forward the page to specified URL



     IITB                                                 - JSP
Actions
<jsp: forward page="ssParameters.jsp">
 <jsp: param name="myParam" value="Amar Patel"/>
 <jsp: param name="Age" value="15"/>
</jsp: forward>

Name: <%= request.getParameter("myParam") %>




    IITB                                           - JSP
JSP implicit objects
• JSP provides several implicit Object

  – 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



    IITB                                          - JSP
Example (implicit Object)
Request :
<a href="queryString.jsp?id=22&name=guru">
request.getQueryString();
<input type="text" name="name">
request.getParameter("name");
<%=request.getRequestURI()%>

Response :
response.sendRedirect("http://www.google.co.in”);
response.setHeader("Cache-Control","no-cache");
response.setContentType("text/html");


    IITB                                            - JSP
Session in jsp
• 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
(i) Session Object
(ii) Cookies
(iii) Hidden Form Fields
(iv) URL Rewriting




  IITB                                               - JSP
Session in jsp
Set Session Attribute
String svalue = request.getParameter("sesvalue_txt");
    if(svalue!=null)
    {

session.setAttribute("sesval",request.getParameter("sesvalue
_txt"));
    }




  IITB                                                  - JSP
Session in jsp
Using Session Attribute
<% if(session.getAttribute("sesval")==null){ %>
     <jsp:forward page = "CreateSessionValue.jsp"/>
     <% } %>
    <h1> Hello <%= (String)session.getAttribute("sesval") %>
</h1>


Remove Session Attribute
<%session.removeAttribute("sesval");%>


  IITB                                                - JSP
Application object in jsp
<% 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>



     IITB                                                          - JSP
References
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html

www.roseindia.net/jsp/jsp.htm

www.jsptutorial.net/

www.jsptut.com/

www.tutorialspoint.com/jsp/index.htm




     IITB                                             - JSP

More Related Content

What's hot

Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)Chitrank Dixit
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorialshiva404
 
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSINGINTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSINGAaqib Hussain
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance JavaDarshit Metaliya
 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jspPriyanka Pradhan
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVAYash Mody
 
Ch. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryCh. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryManolis Vavalis
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharingvikram singh
 

What's hot (20)

Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSINGINTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Ch. 8 script free pages
Ch. 8 script free pagesCh. 8 script free pages
Ch. 8 script free pages
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jsp
 
Jsp tutorial (1)
Jsp tutorial (1)Jsp tutorial (1)
Jsp tutorial (1)
 
Jsp element
Jsp elementJsp element
Jsp element
 
JSP
JSPJSP
JSP
 
19servlets
19servlets19servlets
19servlets
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
 
Ch. 9 jsp standard tag library
Ch. 9 jsp standard tag libraryCh. 9 jsp standard tag library
Ch. 9 jsp standard tag library
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharing
 
Jsp
JspJsp
Jsp
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Ch. 7 beeing a jsp
Ch. 7 beeing a jsp     Ch. 7 beeing a jsp
Ch. 7 beeing a jsp
 
Being a jsp
Being a jsp     Being a jsp
Being a jsp
 

Viewers also liked

Viewers also liked (6)

Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Audio video class room
Audio video class roomAudio video class room
Audio video class room
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
 
Java
JavaJava
Java
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Jsp

JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10Smita B Kumar
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Ayes Chinmay
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSbharathiv53
 
Core web application development
Core web application developmentCore web application development
Core web application developmentBahaa Farouk
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...MathivananP4
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)Fahad Golra
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsKaml Sah
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGESKalpana T
 

Similar to Jsp (20)

JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Jsp
JspJsp
Jsp
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
20jsp
20jsp20jsp
20jsp
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODS
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Jsp
JspJsp
Jsp
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...JavaScript, often abbreviated as JS, is a programming language and core techn...
JavaScript, often abbreviated as JS, is a programming language and core techn...
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
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
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Jsp

  • 1. Java Server Pages Summer Internship – 2012 (Indian Institute of Technology Bombay) Rajavel D (Clicker Software)
  • 2. 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 IITB - JSP
  • 4. 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 IITB - JSP
  • 5. Example JSP • <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 IITB - JSP
  • 6. 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! <% } %> IITB - JSP
  • 7. 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 IITB - JSP
  • 8. 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 --%> IITB - JSP
  • 9. Directives • Directives affect the servlet class itself • A directive has the form: <%@ directive attribute="value" %> • The most useful directive is page, which lets you import packages – Example: <%@ page import="java.util.*" %> IITB - JSP
  • 10. The include directive • The include directive inserts another file into the file being parsed • Syntax: <%@ include file="URL " %> – The URL is treated as relative to the JSP page – If the URL begins with a slash, it is treated as relative to the home directory of the Web server • Example : <%@include file="/jsp/header.jsp"%> IITB - JSP
  • 11. Actions tags • Actions are XML-syntax tags used to control the servlet engine • <jsp:include page="URL " /> – Inserts the relative URL at execution time (not at compile time, like the include directive does) – This is great for rapidly changing data • <jsp:forward page="URL" /> <jsp:forward page="www.google.co.in" /> – Forward the page to specified URL IITB - JSP
  • 12. Actions <jsp: forward page="ssParameters.jsp"> <jsp: param name="myParam" value="Amar Patel"/> <jsp: param name="Age" value="15"/> </jsp: forward> Name: <%= request.getParameter("myParam") %> IITB - JSP
  • 13. JSP implicit objects • JSP provides several implicit Object – 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 IITB - JSP
  • 14. Example (implicit Object) Request : <a href="queryString.jsp?id=22&name=guru"> request.getQueryString(); <input type="text" name="name"> request.getParameter("name"); <%=request.getRequestURI()%> Response : response.sendRedirect("http://www.google.co.in”); response.setHeader("Cache-Control","no-cache"); response.setContentType("text/html"); IITB - JSP
  • 15. Session in jsp • 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 (i) Session Object (ii) Cookies (iii) Hidden Form Fields (iv) URL Rewriting IITB - JSP
  • 16. Session in jsp Set Session Attribute String svalue = request.getParameter("sesvalue_txt"); if(svalue!=null) { session.setAttribute("sesval",request.getParameter("sesvalue _txt")); } IITB - JSP
  • 17. Session in jsp Using Session Attribute <% if(session.getAttribute("sesval")==null){ %> <jsp:forward page = "CreateSessionValue.jsp"/> <% } %> <h1> Hello <%= (String)session.getAttribute("sesval") %> </h1> Remove Session Attribute <%session.removeAttribute("sesval");%> IITB - JSP
  • 18. Application object in jsp <% 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> IITB - JSP