Slide 1 of 30
Web Applications – An Overview
& Servlet Requests and Responses
Slide 2 of 30
Objectives
 Web Client-Server Model
 Evolution of Servlets
 Web Application
 Web Application Development Process
 Servlet API
 Sending Request
 Sending Response
 Servlet Life Cycle
Slide 3 of 30
Advantages of Web Application
 Easier access to information
 Lower maintenance and deployment costs
 Platform independency
 Wider visibility
Slide 4 of 30
Request Message Structure
Slide 5 of 30
Request line
 This component returns the method, resource
information, such as the type and name, and
the HTTP version of the request message.
Slide 6 of 30
Header information
 This component return the User-Agent along
with the Accept header
Slide 7 of 30
Response Message Structure
Slide 8 of 30
Status line
 This element indicates status of the requested
process
Slide 9 of 30
Header information
 The header information contains information
such as server, last modified date, content-
length and content type.
Slide 10 of 30
Request Method
Slide 11 of 30
Limitation of Web Server
 Overloading error
 Unavailability due to maintenance
 Heavy traffic
 Virus and worm attack
Slide 12 of 30
Servlet
 Servlet are java code that are used to add
dynamic content to Web Server
 Servlet gets auto refreshed on receiving a
request each time. A servlet initialisation code is
used only for initialising the Servlet for first
time.
Slide 13 of 30
Advantage of Servlet
Slide 14 of 30
Merits of Servlet
 Enhanced efficiency
 Ease of use
 Powerful
 Portable
 Safe and Cheap
Slide 15 of 30
Demerits of Servlet
 Low level HTML documentation
 UnClear session management
Slide 16 of 30
Web Container Concept
 The web container is a program that manage
execution of servlets and JSP Page
Slide 17 of 30
Web Application Servlet -JSP
Slide 18 of 30
Servlet API – GenericServlet Class
GenericServlet
Class implement
the Servlet and
ServletConfig
Slide 19 of 30
Servlet API – GenericServlet Class
 Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on
the Web, extend HttpServlet instead.
 GenericServlet implements the Servlet and ServletConfig interfaces. GenericServlet
may be directly extended by a servlet, although it's more common to extend a
protocol-specific subclass such as HttpServlet.
 GenericServlet makes writing servlets easier. It provides simple versions of the
lifecycle methods init and destroy and of the methods in the ServletConfig interface.
GenericServlet also implements the log method, declared in the ServletContext
interface.
 To write a generic servlet, you need only override the abstract service method.
Slide 20 of 30
“HttpServlet” Class
 The HttpServlet class provider an abstract class
a create an HTTP Servlet. HttpServlet extend
the GenericServlet
 Two Method process Request
– dopost()
– doget()
Slide 21 of 30
ServletRequest
This interface is for getting data from the client to
the servlet for a service request
 getParameter()
 getAttribute()
 getContentLength()
 getInputStream()
 getServerName()
Slide 22 of 30
HttpServletRequest
HttpServletRequest
extend ServletRequest
Slide 23 of 30
Method of HttpServletRequest Interface
 getCookies()
 getHeader()
 getMethod()
 getPathInfo()
 getAuthType()
 getParametter()
 getParametterNames()
 getParametterValues()
Slide 24 of 30
Request Header
 Accept
 Accept-Charset
 Accept-Encoding
 Accept-Language
 Authorization
Slide 25 of 30
Request Header
 getHeader()
 getHeaders()
 getHeaderNames()
Slide 26 of 30
“ServletResponse” Interface
 The ServletResponse interface define methods
that allow you to retrieve an out put stream to
send data to the Client
Slide 27 of 30
Method of “ServletResponses” Interface
 getContentType()
 getWriter()
 getOutputStream()
 setContentType()
Slide 28 of 30
“HttpServletResponse” Interface
Extend ServletReponse
 addCookie()
 addHeader()
 containtHeader()
 sendError()
 Print()
 sendRedirect()
 encodeRedirect()
Slide 29 of 30
Stage of Servlet Life Cycle
Instatiation
Initialisation
Service
Destroy
Unavaible
The servlet
container create
an object of the
Servlet class
Slide 30 of 30
Summary
 Web Client-Server Model
 Evolution of Servlets
 Web Application
 Web Application Development Process
 Servlet API
 Sending Request
 Sending Response
 Servlet Life Cycle

Session 1 introduction servlet - Giáo trình Bách Khoa Aptech

  • 1.
    Slide 1 of30 Web Applications – An Overview & Servlet Requests and Responses
  • 2.
    Slide 2 of30 Objectives  Web Client-Server Model  Evolution of Servlets  Web Application  Web Application Development Process  Servlet API  Sending Request  Sending Response  Servlet Life Cycle
  • 3.
    Slide 3 of30 Advantages of Web Application  Easier access to information  Lower maintenance and deployment costs  Platform independency  Wider visibility
  • 4.
    Slide 4 of30 Request Message Structure
  • 5.
    Slide 5 of30 Request line  This component returns the method, resource information, such as the type and name, and the HTTP version of the request message.
  • 6.
    Slide 6 of30 Header information  This component return the User-Agent along with the Accept header
  • 7.
    Slide 7 of30 Response Message Structure
  • 8.
    Slide 8 of30 Status line  This element indicates status of the requested process
  • 9.
    Slide 9 of30 Header information  The header information contains information such as server, last modified date, content- length and content type.
  • 10.
    Slide 10 of30 Request Method
  • 11.
    Slide 11 of30 Limitation of Web Server  Overloading error  Unavailability due to maintenance  Heavy traffic  Virus and worm attack
  • 12.
    Slide 12 of30 Servlet  Servlet are java code that are used to add dynamic content to Web Server  Servlet gets auto refreshed on receiving a request each time. A servlet initialisation code is used only for initialising the Servlet for first time.
  • 13.
    Slide 13 of30 Advantage of Servlet
  • 14.
    Slide 14 of30 Merits of Servlet  Enhanced efficiency  Ease of use  Powerful  Portable  Safe and Cheap
  • 15.
    Slide 15 of30 Demerits of Servlet  Low level HTML documentation  UnClear session management
  • 16.
    Slide 16 of30 Web Container Concept  The web container is a program that manage execution of servlets and JSP Page
  • 17.
    Slide 17 of30 Web Application Servlet -JSP
  • 18.
    Slide 18 of30 Servlet API – GenericServlet Class GenericServlet Class implement the Servlet and ServletConfig
  • 19.
    Slide 19 of30 Servlet API – GenericServlet Class  Defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, extend HttpServlet instead.  GenericServlet implements the Servlet and ServletConfig interfaces. GenericServlet may be directly extended by a servlet, although it's more common to extend a protocol-specific subclass such as HttpServlet.  GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.  To write a generic servlet, you need only override the abstract service method.
  • 20.
    Slide 20 of30 “HttpServlet” Class  The HttpServlet class provider an abstract class a create an HTTP Servlet. HttpServlet extend the GenericServlet  Two Method process Request – dopost() – doget()
  • 21.
    Slide 21 of30 ServletRequest This interface is for getting data from the client to the servlet for a service request  getParameter()  getAttribute()  getContentLength()  getInputStream()  getServerName()
  • 22.
    Slide 22 of30 HttpServletRequest HttpServletRequest extend ServletRequest
  • 23.
    Slide 23 of30 Method of HttpServletRequest Interface  getCookies()  getHeader()  getMethod()  getPathInfo()  getAuthType()  getParametter()  getParametterNames()  getParametterValues()
  • 24.
    Slide 24 of30 Request Header  Accept  Accept-Charset  Accept-Encoding  Accept-Language  Authorization
  • 25.
    Slide 25 of30 Request Header  getHeader()  getHeaders()  getHeaderNames()
  • 26.
    Slide 26 of30 “ServletResponse” Interface  The ServletResponse interface define methods that allow you to retrieve an out put stream to send data to the Client
  • 27.
    Slide 27 of30 Method of “ServletResponses” Interface  getContentType()  getWriter()  getOutputStream()  setContentType()
  • 28.
    Slide 28 of30 “HttpServletResponse” Interface Extend ServletReponse  addCookie()  addHeader()  containtHeader()  sendError()  Print()  sendRedirect()  encodeRedirect()
  • 29.
    Slide 29 of30 Stage of Servlet Life Cycle Instatiation Initialisation Service Destroy Unavaible The servlet container create an object of the Servlet class
  • 30.
    Slide 30 of30 Summary  Web Client-Server Model  Evolution of Servlets  Web Application  Web Application Development Process  Servlet API  Sending Request  Sending Response  Servlet Life Cycle

Editor's Notes

  • #4 Easier access to information: Để duyệt web chỉ cần trình duyệt, trình duyệt đã dc tích hợp trong hầu hết các OS. Giao thức của các ứng dụng web là HTTP được hỗ trợ bởi hầu hết các OS. Lower maintenance and deployment costs Không cần cài đặt client, code chỉ cần sửa ở server. Platform independency Wider visibility Truy cập toàn cầu