It is critical to find out how the servlet works for information about the servlet well. Here, we're going to get the inner element approximately the primary servlet program.
The server assessments if the servlet is asked for the primary time.
If yes, web container does the subsequent tasks:
else
The web container calls the distroy technique when it wishes to do away with the servlet along with at time of preventing server or undeploying the project.
The web container is accountable to address the request. Let's see the way it handles the request.
The public carrier technique transforms the ServletRequest item into the HttpServletRequest kind and ServletResponse item into the HttpServletResponse kind. Then, call the carrier technique passing those gadgets. Let's see the inner code:
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { HttpServletRequest request; HttpServletResponse response; try { request = (HttpServletRequest)req; response = (HttpServletResponse)res; } catch(ClassCastException e) { throw new ServletException("non-HTTP request or response"); } service(request, response); }
Checking the type of request is done by protected service Method. And if the request type is get, it calls doget way, if request type is post then, it calls do post method, and So on. The internal codes are given below:
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String method = req.getMethod(); if(method.equals("GET")) { long lastModified = getLastModified(req); if(lastModified == -1L) { doGet(req, resp); } .... //rest of the code } }