This is my first topic in SCWD form.
I have a problem in given below servlet programme that is in doGet method .My tutor says that req and res are HttpServletRequest and HttpServletResponse objects but i think this is absolutely wrong because we can not create objects of Interfaces .Here HttpServletRequest and HttpServletResponse are interfaces.My answer is : req and res are reference variables of these HttpServletRequest and HttpServletResponse type which can take/hold objects of those classes which implements these interfaces directly or indirectly.Am i Right? If yes then which classes 's objects are these?How can we know the name of these classes ?
public class first extends HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException ,IOException
[ February 09, 2008: Message edited by: pradeep singh ]
Am i Right?
Yes, but I would not say that your tutor is wrong. You're making a fuss of little things. Your tutor wants to put it simply. It took me some time to understand what you were trying to say, while I understood straight away what your tutor is saying
If yes then which classes 's objects are these?
The web container implements these interfaces.
How can we know the name of these classes ?
request.getClass().getName(). You'll get different classes depending on which container you are using.
Your understanding is correct, req and res are objects of classes implementing these interfaces,
container creates these objects and calls the servlet's service() method, passing the req and res objects as arguments,
To be specific to your question, regarding name of the classes implementing these interfaces, it depends on the web container you are using.
The implementations of these interfaces are not part of the J2EE spec, but depends on users of the spec. Tomcat is considered a reference implementation - i.e. it is considered to be implements the specification to the full and in the correct manner.
In tomcat, Class HttpServletRequestImpl implements HttpServletRequest interface, same way for response.
others- pls correct me if my understanding is not correct
Thanks to you all
I want some more people's suggestions or views on this above.
It is the container's responsibility to provide implementation for these interfaces and they vary from provider to provider.
All you care is to get the information from the request and response objects and process it.