✔ SERVLET CHAPTERS:-
1. Servlet Arctitecture Overview
2. Life cycle of Servlet
3. Servlet Interface
4. Generic Servlet Class
5. Http Servlet Class
6. Deployment Descriptor Webxml
7. Welcome File List In Webxml
8. Load On Startup in Webxml
9. Request Dispatcher Interface
10. Sendre Direct In Servlet
11. Servlet init Parameters
12. Servlet context Parameters
13. Servlet Hello World Example
14. Session Management Cookies
15. Cookie in Servlet
16. Hidden Field In Servlet
17. URL rewriting In Servlet
18. Http session In Servlet
19. Servlet Filter In Java
20. Filter Config Interface
1. Servlet Arctitecture Overview
2. Life cycle of Servlet
3. Servlet Interface
4. Generic Servlet Class
5. Http Servlet Class
6. Deployment Descriptor Webxml
7. Welcome File List In Webxml
8. Load On Startup in Webxml
9. Request Dispatcher Interface
10. Sendre Direct In Servlet
11. Servlet init Parameters
12. Servlet context Parameters
13. Servlet Hello World Example
14. Session Management Cookies
15. Cookie in Servlet
16. Hidden Field In Servlet
17. URL rewriting In Servlet
18. Http session In Servlet
19. Servlet Filter In Java
20. Filter Config Interface
Generic Servlet Class in Java: Previous Next: Deployment Descriptor Webxml File
HttpServlet class in java
HttpServlet class:
HttpServlet class extends the GenericServlet. It is protocol-dependent.
public abstract class HttpServlet extends GenericServlet
HttpServlet class is in javax.servlet.http package (javax.servlet.http.HttpServlet).
Methods of HttpServlet class:
1. service(ServletRequest req,ServletResponse res):Dispatches the requests to the protected service method. It converts the request and response object into http type before dispatching request.
Syntax: public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
2. service(HttpServletRequest req, HttpServletResponse res):Receives HTTP requests from the public service method and dispatches the request to the doXXX methods defined in this class.
Syntax: protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
3. doGet(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling GET requests.
Syntax: protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
4. doPost(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling POST requests.
Syntax: protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
5. doHead(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling HEAD requests.
Syntax: protected void doHead(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
6. doOptions(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling OPTIONS requests.
Syntax: protected void doOptions(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
7. doPut(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling PUT requests.
Syntax: protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
8. doTrace(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling TRACE requests.
Syntax: protected void doTrace(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
9. doDelete(HttpServletRequest req, HttpServletResponse res): This method is called by web container for handling DELETE requests.
Syntax: protected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
10. getLastModified(HttpServletRequest req): It returns the time the HttpServletRequest object was last modified since midnight January 1, 1970 GMT. It returns a negative number if time is unknown.
Syntax: protected long getLastModified(HttpServletRequest req)
Servlet “Hello World” example by extending HttpServlet class.
HelloWorld.java
web.xml