This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello ranchers, I was justing going thru the API. I found that the GenericServlet Abstract class has a method for getParameter(String). I just want to know, that when we write request.getParameter(String), does the container call the method from GenericServlet. I am preety confused, because int the doGet(HttpServletRequest, HttpServletResponse), both these are Interfaces, so where is the implementation. ???, I just trying the figure out, how the whole thing works!!, can anyone put some light on it....thanks in advance... Shashank
Hi Shashank javax.servlet.GenericServlet does not have any function with signature getParameter(String). Although it has one function with signature getInitParameter(java.lang.String name). This function is used to get the init parameter of servlet config. Servlet config parameters are defined in deployment descriptor.
When a browser sends the request to a servler the container creates two Object implementing javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServetRespose , creates a new thread and calles the service method of servlet passing these parameters.
These same are also passed in doGet(HttpServletRequest request ,HttpServletResponse response) method.
Joined: May 15, 2005
but we get config values from servletConfig.getInitParameter(java.lang.String name). So the method getInitParameter(java.lang.String name) is called from the servletConfig interface. Then why does Generic Servlet has this method. Am i thinking in right direction??
Joined: Jun 03, 2006
hi Shashank You are thiking in right direction , but have you ever thought the reson of existance of javax.servlet.GenericServlet. This class implements all the functions of javax.servlet.Servlet and javax.servlet.ServletConfig interfaces except servlet(ServletRequest,ServletResponse) method of javax.servlet.Servlet.
That is why this also has same methods as of javax.servlet.Servlet and javax.servlet.ServletConfig.