This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes HttpServletRequest can have object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest can have object?" Watch "HttpServletRequest can have object?" New topic
Author

HttpServletRequest can have object?

suresh midde
Greenhorn

Joined: Aug 22, 2008
Posts: 25
Hi,

I have a doubt regarding HttpServletRequest.When a servlet container receives request from the client, it was mentioned like , the servlet container creates objects of HttpServletRequest and HttpServletResponse , and the same are passed to the service method of life cycle.


I have a doubt, since HttpServletRequest, HttpServletResponse are interfaces,
if i am right, we cannot create objects of interfaces.Then can anyone let me understand this?


Regards
Suresh
sangram mhatre
Greenhorn

Joined: Apr 02, 2005
Posts: 15
Every container implements the HttpServletRequest and HttpServletResponse
interfaces , a container actually creates objects of these implementation
objects ,

HttpServletRequest httpServletRequestImpl = new HttpServletRequestImpl();
HttpServletResponse httpServletResponseImpl = new HttpServletResponseImpl();

and populates these and then calls the service method .
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The Servlet Container would have made their own classes which implement the interfaces, then pass instances of those implementations on to the servlet code. This is important, basic Java (basic Object Oriented Programming) stuff. See the Java Tutorial and Here is an example of some code using an interface, and some classes that implement the interface (much like what you do with servlets)


Steve
 
 
subject: HttpServletRequest can have object?