• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in the parameters of doGet method

 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all
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 ?







import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class first extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException ,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();


out.println("hello World");

}

}

[ February 09, 2008: Message edited by: pradeep singh ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amar Nath Verma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good question,

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
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks to you all
I want some more people's suggestions or views on this above.
 
Meera Pallath
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with the replies.
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic