SlideShare une entreprise Scribd logo
1  sur  26
Core Web Application
Development Using Servlet &
JSP
Bahaa Farouk
                       Organized
                          By
Agenda
• Servlet
   – What is Java Servlet?
   – Servlet Life Cycle
   – Client Interaction & Session
• JSP
   –   What’s JSP?
   –   JSP Life Cycle
   –   What’s JSP Contains?
   –   JSP Scope & Implicit Objects
• Why Servlet & JSP?
Web Application Development?
Agenda
• Servlet
   – What is Java Servlet?
   – Servlet Life Cycle
   – Client Interaction & Session
• JSP
   –   What’s JSP?
   –   JSP Life Cycle
   –   What’s JSP Contains?
   –   JSP Scope & Implicit Objects
• Why Servlet & JSP?
What is Java Servlet?
• An alternate form of server-side computation that
  uses Java
• The Web server is extended to support an API, and
  then Java programs use the API to create dynamic
  web pages
• Using Java servlets provides a platform-independent
  replacement for CGI scripts.
• Servlets can be embedded in many different servers
  because the servlet API, which you use to write
  servlets, assumes nothing about the server's
  environment or protocol.
Servlet Life Cycle
• Initialization
   – the servlet engine loads the servlet’s *.class file in the JVM
     memory space and initializes any objects
• Execution
   – when a servlet request is made,
      • a ServletRequest object is sent with all information about the
        request
      • a ServletResponse object is used to return the response
• Destruction
   – the servlet cleans up allocated resources and shuts down
Client Interaction
• When a servlet accepts a call from a client,
  it receives two objects:
  – A ServletRequest, which encapsulates the
    communication from the client to the server.
  – A ServletResponse, which encapsulates the
    communication from the servlet back to the
    client.
• ServletRequest and ServletResponse are
  interfaces defined by the javax.servlet
  package.
Request Header Example
Request Parameters
Cookies
Session Capabilities
• Session tracking is a mechanism that servlets use to
  maintain state about a series of requests from the
  same user(that is, requests originating from the
  same browser) across some period of time.
• Session tracking capabilities. The servlet writer can
  use these APIs to maintain state between the servlet
  and the client that persists across multiple
  connections during some time period.
Sessions
Agenda
• Servlet
   – What is Java Servlet?
   – Servlet Life Cycle
   – Client Interaction & Session
• JSP
   –   What’s JSP?
   –   JSP Life Cycle
   –   What’s JSP Contains?
   –   JSP Scope & Implicit Objects
• Why Servlet & JSP?
What is JSP?
• A Java Servlet is a Java program that is run on the
  server
   – There are Java classes for retrieving HTTP requests and
     returning HTTP responses
   – Must return an entire HTML page, so all tuning of the page
     must be done in a Java program that needs to be re-
     compiled
• Java Server Pages (JSP)
   – use HTML and XML tags to design the page and JSP scriplet
     tags to generate dynamic content (Easier for separation
     between designer & developer)
   – use Java Beans and useful built-in objects for more
     convenience
JSP Life Cycle
• JSP page (MyFirstJSP.jsp)
   –   Translated to Servle (MyFirstJSP.servlet)
   –   Compiled to class (MyFirstJSP.class)
   –   Loaded into memory (Initialization)
   –   Execution (repeats)
   –   Destruction


• Any change in JSP page automatically repeats the
  whole life cycle.
Introduction
 • A Java Servlet is a Java program that is run on the
   server
    – There are Java classes for retrieving HTTP requests and
      returning HTTP responses
 • Java Server Pages (JSP)
    – use HTML and XML tags to design the page and JSP scriplet
      tags to generate dynamic content
    – use Java Beans, which are reusable components that are
      invoked by scriplets
What do JSPs contain?
• Template data
  – Everything other than elements (eg. Html tags)
• Elements
  – based on XML syntax
     • <somejsptag attribute name=“atrribute value”> BODY
       </somejsptag>
  – Directives
  – Scripting
     • Declarations
     • Scriptles
     • Expressions
  – Standard Actions
Directives
 • <%@ directivename attribute=“value”
   attribute=“value” %>
 • The page directive
    – <%@ page ATTRIBUTES %>
    – language, import, Buffer, errorPage,…
    – <%@ page languange=“java”
      import=“java.rmi.*,java.util.*” %>
 • The include directive
    – <%@ include file=“Filename” %>
    – the static file name to include (included at translation
      time)
 • The taglib directive
    – <% taglib uri=“taglibraryURI” prefix=“tagPrefix” %>
Scripting
(Declaration, Expressions, Scriptlets)
 • <%! . . %> declares variables or methods
    – define class-wide variables
    – <%! int i = 0; %>
    – <%! int a, b; double c: %>
    – <%! Circle a = new Circle(2.0); %>
    – You must declare a variable or method in a jsp page before
      you use it
    – The scope of a declaration is the jsp file, extending to all
      includes

 • <%= . . %> defines an expression and casts the result
   as a string
Scripting II
  • <%= . . %> can contain any language expression, but
    without a semicolon, e.g.
  • <%= Math.sqrt(2) %>
  • <%= items[I] %>
  • <%= a + b + c %>
  • <%= new java.util.Date() %>
  • <% . . %> can handle declarations (page scope),
    expressions, or any other type of code fragment
  • <% for(int I = 0; I < 10; I++) {
        out.println(“<B> Hello World: “ + I);       } %>
JSP and Scope
• Page - objects with page scope are accessible only within the
  page where they are created
• Request - objects with request scope are accessible from
  pages processing the same request where they were created
• Session - ojbects with session scope are accessible from pages
  processing requests that are in the same session as the one in
  which they were created
• Application - objects with application scope are accessible
  from pages processing requests that are in the same
  application as the one in which they were created
• All the different scopes behave as a single name space
Implicit Objects
• These objects do not need to be declared or instantiated by
  the JSP author, but are provided by the container (jsp engine)
  in the implementation class
• request Object (javax.servlet.ServletRequest)
• response Object (javax.servlet.ServletResponse)
• session Object (javax.servlet.http.HttpSession)
• application Object
• out Object
• config Object
• page Object
• pageContext Object (javax.servlet.jsp.PageContext)
• exception
Number guess - Browser Output
Agenda
• Servlet
   – What is Java Servlet?
   – Servlet Life Cycle
   – Client Interaction & Session
• JSP
   –   What’s JSP?
   –   JSP Life Cycle
   –   What’s JSP Contains?
   –   JSP Scope & Implicit Objects
• Why Servlet & JSP?
Why Servlet/JSP?
What is an Enterprise Application?
 •   Reliable
 •   Scalable
 •   Maintainable
 •   Manageable

     – If you are developing an Enterprise Application for
     whose daily transactions are millions?
        • Performance? Scalability? Reliability?
Questions ?

Contenu connexe

Tendances

Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jspAnkit Minocha
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
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 servletsJavaEE Trainers
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.pptVMahesh5
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersFernando Gil
 

Tendances (20)

Servlets
ServletsServlets
Servlets
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
Servlet
Servlet Servlet
Servlet
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Java servlets
Java servletsJava servlets
Java servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
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
 
Servlets
ServletsServlets
Servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlets
ServletsServlets
Servlets
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and Containers
 

En vedette

Be Part Of Software Development
Be Part Of Software DevelopmentBe Part Of Software Development
Be Part Of Software DevelopmentBahaa Farouk
 
Career building and Skills Development
Career building and Skills DevelopmentCareer building and Skills Development
Career building and Skills DevelopmentBahaa Farouk
 
SCRUM Development Process
SCRUM Development ProcessSCRUM Development Process
SCRUM Development ProcessBahaa Farouk
 
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...Ravindu Sandeepa
 
Scrum Agile Methodlogy
Scrum Agile MethodlogyScrum Agile Methodlogy
Scrum Agile MethodlogyBahaa Farouk
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
Web Application Development
Web Application DevelopmentWeb Application Development
Web Application DevelopmentWhytespace Ltd.
 
Oracle ADF Overview
Oracle ADF OverviewOracle ADF Overview
Oracle ADF OverviewBahaa Farouk
 
Agile Overview Session
Agile Overview SessionAgile Overview Session
Agile Overview SessionBahaa Farouk
 
Web Application Development Fundamentals
Web Application Development FundamentalsWeb Application Development Fundamentals
Web Application Development FundamentalsMohammed Makhlouf
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Web Development on Web Project Presentation
Web Development on Web Project PresentationWeb Development on Web Project Presentation
Web Development on Web Project PresentationMilind Gokhale
 
Ppt of web development
Ppt of web developmentPpt of web development
Ppt of web developmentbethanygfair
 
Website Development and Design Proposal
Website Development and Design ProposalWebsite Development and Design Proposal
Website Development and Design ProposalCreative 3D Design
 
java Project report online banking system
java Project report online banking systemjava Project report online banking system
java Project report online banking systemVishNu KuNtal
 

En vedette (19)

M-Brokrage
M-BrokrageM-Brokrage
M-Brokrage
 
Be Part Of Software Development
Be Part Of Software DevelopmentBe Part Of Software Development
Be Part Of Software Development
 
QualiTech Profile
QualiTech ProfileQualiTech Profile
QualiTech Profile
 
Career building and Skills Development
Career building and Skills DevelopmentCareer building and Skills Development
Career building and Skills Development
 
Being Architect
Being ArchitectBeing Architect
Being Architect
 
SCRUM Development Process
SCRUM Development ProcessSCRUM Development Process
SCRUM Development Process
 
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...
System requirement specification report(srs) T/TN/Gomarankadawala Maha vidyal...
 
Scrum Agile Methodlogy
Scrum Agile MethodlogyScrum Agile Methodlogy
Scrum Agile Methodlogy
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Web Application Development
Web Application DevelopmentWeb Application Development
Web Application Development
 
Oracle ADF Overview
Oracle ADF OverviewOracle ADF Overview
Oracle ADF Overview
 
Agile Overview Session
Agile Overview SessionAgile Overview Session
Agile Overview Session
 
ESB Overview
ESB OverviewESB Overview
ESB Overview
 
Web Application Development Fundamentals
Web Application Development FundamentalsWeb Application Development Fundamentals
Web Application Development Fundamentals
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Web Development on Web Project Presentation
Web Development on Web Project PresentationWeb Development on Web Project Presentation
Web Development on Web Project Presentation
 
Ppt of web development
Ppt of web developmentPpt of web development
Ppt of web development
 
Website Development and Design Proposal
Website Development and Design ProposalWebsite Development and Design Proposal
Website Development and Design Proposal
 
java Project report online banking system
java Project report online banking systemjava Project report online banking system
java Project report online banking system
 

Similaire à Core web application development

Similaire à Core web application development (20)

Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 
Coursejspservlets00
Coursejspservlets00Coursejspservlets00
Coursejspservlets00
 
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...
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
20jsp
20jsp20jsp
20jsp
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Advance java session 9
Advance java session 9Advance java session 9
Advance java session 9
 
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
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
Jsp
JspJsp
Jsp
 
Advance java session 10
Advance java session 10Advance java session 10
Advance java session 10
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
Ch. 7 beeing a jsp
Ch. 7 beeing a jsp     Ch. 7 beeing a jsp
Ch. 7 beeing a jsp
 
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
 
005432796.pdf
005432796.pdf005432796.pdf
005432796.pdf
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Core web application development

  • 1. Core Web Application Development Using Servlet & JSP Bahaa Farouk Organized By
  • 2. Agenda • Servlet – What is Java Servlet? – Servlet Life Cycle – Client Interaction & Session • JSP – What’s JSP? – JSP Life Cycle – What’s JSP Contains? – JSP Scope & Implicit Objects • Why Servlet & JSP?
  • 4. Agenda • Servlet – What is Java Servlet? – Servlet Life Cycle – Client Interaction & Session • JSP – What’s JSP? – JSP Life Cycle – What’s JSP Contains? – JSP Scope & Implicit Objects • Why Servlet & JSP?
  • 5. What is Java Servlet? • An alternate form of server-side computation that uses Java • The Web server is extended to support an API, and then Java programs use the API to create dynamic web pages • Using Java servlets provides a platform-independent replacement for CGI scripts. • Servlets can be embedded in many different servers because the servlet API, which you use to write servlets, assumes nothing about the server's environment or protocol.
  • 6. Servlet Life Cycle • Initialization – the servlet engine loads the servlet’s *.class file in the JVM memory space and initializes any objects • Execution – when a servlet request is made, • a ServletRequest object is sent with all information about the request • a ServletResponse object is used to return the response • Destruction – the servlet cleans up allocated resources and shuts down
  • 7. Client Interaction • When a servlet accepts a call from a client, it receives two objects: – A ServletRequest, which encapsulates the communication from the client to the server. – A ServletResponse, which encapsulates the communication from the servlet back to the client. • ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.
  • 11. Session Capabilities • Session tracking is a mechanism that servlets use to maintain state about a series of requests from the same user(that is, requests originating from the same browser) across some period of time. • Session tracking capabilities. The servlet writer can use these APIs to maintain state between the servlet and the client that persists across multiple connections during some time period.
  • 13. Agenda • Servlet – What is Java Servlet? – Servlet Life Cycle – Client Interaction & Session • JSP – What’s JSP? – JSP Life Cycle – What’s JSP Contains? – JSP Scope & Implicit Objects • Why Servlet & JSP?
  • 14. What is JSP? • A Java Servlet is a Java program that is run on the server – There are Java classes for retrieving HTTP requests and returning HTTP responses – Must return an entire HTML page, so all tuning of the page must be done in a Java program that needs to be re- compiled • Java Server Pages (JSP) – use HTML and XML tags to design the page and JSP scriplet tags to generate dynamic content (Easier for separation between designer & developer) – use Java Beans and useful built-in objects for more convenience
  • 15. JSP Life Cycle • JSP page (MyFirstJSP.jsp) – Translated to Servle (MyFirstJSP.servlet) – Compiled to class (MyFirstJSP.class) – Loaded into memory (Initialization) – Execution (repeats) – Destruction • Any change in JSP page automatically repeats the whole life cycle.
  • 16. Introduction • A Java Servlet is a Java program that is run on the server – There are Java classes for retrieving HTTP requests and returning HTTP responses • Java Server Pages (JSP) – use HTML and XML tags to design the page and JSP scriplet tags to generate dynamic content – use Java Beans, which are reusable components that are invoked by scriplets
  • 17. What do JSPs contain? • Template data – Everything other than elements (eg. Html tags) • Elements – based on XML syntax • <somejsptag attribute name=“atrribute value”> BODY </somejsptag> – Directives – Scripting • Declarations • Scriptles • Expressions – Standard Actions
  • 18. Directives • <%@ directivename attribute=“value” attribute=“value” %> • The page directive – <%@ page ATTRIBUTES %> – language, import, Buffer, errorPage,… – <%@ page languange=“java” import=“java.rmi.*,java.util.*” %> • The include directive – <%@ include file=“Filename” %> – the static file name to include (included at translation time) • The taglib directive – <% taglib uri=“taglibraryURI” prefix=“tagPrefix” %>
  • 19. Scripting (Declaration, Expressions, Scriptlets) • <%! . . %> declares variables or methods – define class-wide variables – <%! int i = 0; %> – <%! int a, b; double c: %> – <%! Circle a = new Circle(2.0); %> – You must declare a variable or method in a jsp page before you use it – The scope of a declaration is the jsp file, extending to all includes • <%= . . %> defines an expression and casts the result as a string
  • 20. Scripting II • <%= . . %> can contain any language expression, but without a semicolon, e.g. • <%= Math.sqrt(2) %> • <%= items[I] %> • <%= a + b + c %> • <%= new java.util.Date() %> • <% . . %> can handle declarations (page scope), expressions, or any other type of code fragment • <% for(int I = 0; I < 10; I++) { out.println(“<B> Hello World: “ + I); } %>
  • 21. JSP and Scope • Page - objects with page scope are accessible only within the page where they are created • Request - objects with request scope are accessible from pages processing the same request where they were created • Session - ojbects with session scope are accessible from pages processing requests that are in the same session as the one in which they were created • Application - objects with application scope are accessible from pages processing requests that are in the same application as the one in which they were created • All the different scopes behave as a single name space
  • 22. Implicit Objects • These objects do not need to be declared or instantiated by the JSP author, but are provided by the container (jsp engine) in the implementation class • request Object (javax.servlet.ServletRequest) • response Object (javax.servlet.ServletResponse) • session Object (javax.servlet.http.HttpSession) • application Object • out Object • config Object • page Object • pageContext Object (javax.servlet.jsp.PageContext) • exception
  • 23. Number guess - Browser Output
  • 24. Agenda • Servlet – What is Java Servlet? – Servlet Life Cycle – Client Interaction & Session • JSP – What’s JSP? – JSP Life Cycle – What’s JSP Contains? – JSP Scope & Implicit Objects • Why Servlet & JSP?
  • 25. Why Servlet/JSP? What is an Enterprise Application? • Reliable • Scalable • Maintainable • Manageable – If you are developing an Enterprise Application for whose daily transactions are millions? • Performance? Scalability? Reliability?