Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session-02.

Similar presentations


Presentation on theme: "Session-02."— Presentation transcript:

1 Session-02

2 Servlet API The javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet api. javax.servlet javax.servlet.http

3 Servlet Jar File

4 javax.servlet

5 Interfaces in javax.servlet package
ServletRequest ServletResponse RequestDispatcher ServletConfig ServletContext SingleThreadModel Filter FilterConfig FilterChain ServletRequestListener ServletRequestAttributeListener ServletContextListener ServletContextAttributeListener

6 Classes in javax.servlet package
GenericServlet ServletInputStream ServletOutputStream ServletRequestWrapper ServletResponseWrapper ServletRequestEvent ServletContextEvent ServletRequestAttributeEvent ServletContextAttributeEvent ServletException UnavailableException

7 Continue...

8 javax.servlet. http

9 Interfaces in javax.servlet.http package
HttpServletRequest HttpServletResponse HttpSession HttpSessionListener HttpSessionAttributeListener HttpSessionBindingListener HttpSessionActivationListener HttpSessionContext (deprecated now)

10 Classes in javax.servlet.http package
HttpServlet Cookie HttpServletRequestWrapper HttpServletResponseWrapper HttpSessionEvent HttpSessionBindingEvent HttpUtils (deprecated now)

11 Continue...

12 How to use servlet api classes?

13 Difference between javax.servlet & javax.servlet.http
All classes & interfaces inside javax.servlet package are protocol Independent. All classes & interfaces inside javax.servlet.http package are Protocol dependent(HTTP).

14 Servlet Interface Servlet interface provides common behaviour to all the servlets. Servlet interface needs to be implemented for creating any servlet (either directly or indirectly). Defines methods that all servlets must implement. A servlet is a small Java program that runs within a Web server. To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet OR an HTTP servlet that extends javax.servlet.http.HttpServlet.

15 Continue...

16 Continue...

17 Method Detail Init Called by the servlet container to indicate to a servlet that the servlet is being placed into service. The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests. The servlet container cannot place the servlet into service if the init method Throws a ServletException Does not return within a time period defined by the Web server

18 Method Detail getServletConfig
Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. Implementations of this interface are responsible for storing the ServletConfig object so that this method can return it. Returns: the ServletConfig object that initializes this servlet

19 Method Detail service Called by the servlet container to allow the servlet to respond to a request. This method is only called after the servlet's init() method has completed successfully. Servlets typically run inside multithreaded servlet containers that can handle multiple requests concurrently.

20 Method Detail getServletInfo
Returns information about the servlet, such as author, version, and copyright. The string that this method returns should be plain text and not markup of any kind (such as HTML, XML, etc.). Returns: a String containing servlet information

21 Method Detail destroy Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.

22 Life Cycle of a Servlet (Servlet Life Cycle)
The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet: Servlet class is loaded. Servlet instance is created. init method is invoked. service method is invoked. destroy method is invoked.

23 Continue... The servlet is constructed, then initialized with the init method. Any calls from clients to the service method are handled. The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized.

24 Continue...

25 Continue...

26 Continue...

27 Life Cycle of a Servlet (Servlet Life Cycle) with HTTP

28 Servlet Example by implementing Servlet interface
First.txt


Download ppt "Session-02."

Similar presentations


Ads by Google