*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getParameter() in GenericServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getParameter() in GenericServlet" Watch "getParameter() in GenericServlet" New topic
Author

getParameter() in GenericServlet

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
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


SCJP 1.4, SCWCD 1.4, SCBCD 1.5
salil verma
Greenhorn

Joined: Jun 03, 2006
Posts: 22
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.
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
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??
salil verma
Greenhorn

Joined: Jun 03, 2006
Posts: 22
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.
salil verma
Greenhorn

Joined: Jun 03, 2006
Posts: 22
The class declaration of javax.servlet.GenericServlet is

public abstract class GenericServlet
extends java.lang.Object
implements Servlet, ServletConfig, java.io.Serializable

you can understand the same that i wanted to express
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
thanks, now I get it...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getParameter() in GenericServlet
 
Similar Threads
Null Pointer Exception
How get the Logger from a servlet?
URGENT.....Tips for Answers from Who have already Appeared.
Servlets
Doubt about ServletRequest Interface