wood burning stoves 2.0*
The moose likes Servlets and the fly likes wha is the type of the objects created by container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "wha is the type of the objects created by container" Watch "wha is the type of the objects created by container" New topic
Author

wha is the type of the objects created by container

Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
In Head First Servlet and JSp book, it says that,
The container sees that the request is for the servlet and creates two objects, HttpServletRequest and HttpServletResponse.

And the object is passed to service() which inturn pass the objects to doXXX().

But what is the actual type of the two objects that are created.. I cant be of the type HttpServletRequest ,HttpServletResponse because they are interfaces .

I am confused. Please correct me
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

They will be whatever classes the container provides that implements these interfaces.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
Paul Sturrock wrote:They will be whatever classes the container provides that implements these interfaces.

Could you please explain this... I could not understand
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3029
    
  35

It is vendor-specific - i.e. specific to the container provider.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What you are seeing is just how interfaces work. Something must implement them because, as you've rightly noticed, you cannot instantiate an interface. The Servlet container (e.g. Tomcat) is what provides the implementation. So they are of the type HttpServletRequest and HttpServletResponse (because they inmplement those interfaces), but their concrete implementation will be something else. As far as you are a Servlet/JSP writer you don't need to know/care what that implementation, because you will never use it directly.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're still curious and want to see exactly what classes are implementing these types in your container, paste the following two lines into a JSP and hit it with your browser:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
Thanks guys , Now things are clear..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wha is the type of the objects created by container
 
Similar Threads
Threads
HttpServletRequest object
How container Handle request
Clarification required on Request and Response object being availabe for Garbage Collection
unable to retrieve cookies & logout properly