Session 1 introduction servlet - Giáo trình Bách Khoa Aptech
-
Upload
hoc-lap-trinh-web -
Category
Technology
-
view
1.355 -
download
2
description
Transcript of Session 1 introduction servlet - Giáo trình Bách Khoa Aptech
![Page 1: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/1.jpg)
Slide 1 of 30
Web Applications – An Overview& Servlet Requests and Responses
![Page 2: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/2.jpg)
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
![Page 3: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/3.jpg)
Slide 3 of 30
Advantages of Web Application
Easier access to information Lower maintenance and deployment costs Platform independency Wider visibility
![Page 4: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/4.jpg)
Slide 4 of 30
Request Message Structure
![Page 5: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/5.jpg)
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.
![Page 6: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/6.jpg)
Slide 6 of 30
Header information This component return the User-Agent along
with the Accept header
![Page 7: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/7.jpg)
Slide 7 of 30
Response Message Structure
![Page 8: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/8.jpg)
Slide 8 of 30
Status line This element indicates status of the requested
process
![Page 9: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/9.jpg)
Slide 9 of 30
Header information The header information contains information
such as server, last modified date, content-length and content type.
![Page 10: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/10.jpg)
Slide 10 of 30
Request Method
![Page 11: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/11.jpg)
Slide 11 of 30
Limitation of Web Server Overloading error Unavailability due to maintenance Heavy traffic Virus and worm attack
![Page 12: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/12.jpg)
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.
![Page 13: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/13.jpg)
Slide 13 of 30
Advantage of Servlet
![Page 14: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/14.jpg)
Slide 14 of 30
Merits of Servlet Enhanced efficiency Ease of use Powerful Portable Safe and Cheap
![Page 15: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/15.jpg)
Slide 15 of 30
Demerits of Servlet Low level HTML documentation UnClear session management
![Page 16: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/16.jpg)
Slide 16 of 30
Web Container Concept The web container is a program that manage
execution of servlets and JSP Page
![Page 17: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/17.jpg)
Slide 17 of 30
Web Application Servlet -JSP
![Page 18: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/18.jpg)
Slide 18 of 30
Servlet API – GenericServlet Class
GenericServlet Class implement the Servlet and ServletConfig
![Page 19: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/19.jpg)
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.
![Page 20: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/20.jpg)
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()
![Page 21: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/21.jpg)
Slide 21 of 30
ServletRequestThis interface is for getting data from the client to
the servlet for a service request getParameter() getAttribute() getContentLength() getInputStream() getServerName()
![Page 22: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/22.jpg)
Slide 22 of 30
HttpServletRequest
HttpServletRequest extend ServletRequest
![Page 23: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/23.jpg)
Slide 23 of 30
Method of HttpServletRequest Interface
getCookies() getHeader() getMethod() getPathInfo() getAuthType() getParametter() getParametterNames() getParametterValues()
![Page 24: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/24.jpg)
Slide 24 of 30
Request Header Accept Accept-Charset Accept-Encoding Accept-Language Authorization
![Page 25: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/25.jpg)
Slide 25 of 30
Request Header getHeader() getHeaders() getHeaderNames()
![Page 26: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/26.jpg)
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
![Page 27: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/27.jpg)
Slide 27 of 30
Method of “ServletResponses” Interface
getContentType() getWriter() getOutputStream() setContentType()
![Page 28: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/28.jpg)
Slide 28 of 30
“HttpServletResponse” Interface
Extend ServletReponse addCookie() addHeader() containtHeader() sendError() Print() sendRedirect() encodeRedirect()
![Page 29: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/29.jpg)
Slide 29 of 30
Stage of Servlet Life Cycle
Instatiation
Initialisation
Service
Destroy
Unavaible
The servlet container create an object of the Servlet class
![Page 30: Session 1 introduction servlet - Giáo trình Bách Khoa Aptech](https://reader035.fdocuments.in/reader035/viewer/2022081413/54625eddb4af9f5d1c8b479e/html5/thumbnails/30.jpg)
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