954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How RequestDispature actually work ?

RequestDispature red = request.getRequestDispature("xyz");
red.forward(req,res);


in this simple example RequestDispature is INTERFACE..! "red" is reference for that , but whose instance it actually holds ???
"forward" and "include" methods are of RequestDispature interface...but where they are implemented ??? in which class ?? which class implement this interface ???

Can anyone explain this code completely ???
From beginning ...as i am newbie in this technology...!
NO PROPER BACKGROUND PROCESS IS EXPLAINED IN ANY BOOK...!
--------------------------------------------------------------------------------

Another query
------------
HttpServletRequest is also an Interface whose Ref is "request" but in that whose object / instance is held ???object of request from client ??? is it generated by container ? while getting an request for particular servlet?

rushi3311
Newbie Poster
10 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

RequestDispature red = request.getRequestDispature("xyz");

What happens here is that the getRequestDispature method is called on the object request. Somewhere in that method it obtains an instance of some class that implements RequestDispature. Nothing in that line of code tells you what class is or how it gets it, all you know is that it implements RequestDispature. Because you are assigning that result to a variable of type RequestDispature everything is OK.
If you want to know more you can look at the documentation for getRequestDispature, and see how it declares its return type. Maybe that's just RequestDispature, or maybe it names an actual class that implements RequestDispature. Also at runtime you could print red.getClass() which will tell you exactly what kind of object was returned from request.getRequestDispature

This is a common thing in Java - for example you may have a method
public List getSomeStuff()
List is an interface, so you can use all its methods on the returned List. But inside getSomeStuff you will find an instance of ArrayList, or LinkedList, etc. It may even return a different class depending on some internal criteria.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: