• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in the parameters of doGet method

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks to you all
I want some more people's suggestions or views on this above.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic