posted 10 years ago
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 ?
[ February 09, 2008: Message edited by: pradeep singh ]
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 ]
SCJP 5.0(75%), SCWCD 5.0(88%)
posted 10 years ago
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
The web container implements these interfaces.
request.getClass().getName(). You'll get different classes depending on which container you are using.
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.
[My Blog]
All roads lead to JavaRanch
posted 10 years ago
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
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<br/>Amar Nath Verma<br/><a href="http://www.amarnathverma.com" target="_blank" rel="nofollow">http://www.amarnathverma.com</a><br/>SCJP 1.4, SCWCD 5, Preparing for SCEA
pradeep singh
Ranch Hand
Posts: 339

His brain is the size of a cherry pit! About the size of this ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|