wood burning stoves 2.0*
The moose likes Servlets and the fly likes Why this request method can be used in this way?! 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 "Why this request method can be used in this way?!" Watch "Why this request method can be used in this way?!" New topic
Author

Why this request method can be used in this way?!

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi everyone:
I have a question that puzzle me all the time.I want to get the answer exactly.
There is a method in servlet:"PrintWriter out=response.getWriter();"The response be passed into the method using--->void doGet(HttpServletRequest request,HttpServletResponse response){
PrintWriter out=response.getWriter();
...............................
}
My problem is the HttpServletResponse is a interface and the response is a interface also in this method.But the response can invoke its parent interface ServletResponse's method "getWriter()"?!The ServletResponse interface is not been implements and its method is blank!Why the HttpServletResponse interface can invoke the "getWriter()" method?I think it there should be a class that it implements the ServletResponse interface method and so I can use it.But there isn't even I find all the interface in javax.servlet* and javax.servlet.http.*.Can anyone help me answer this question?! Thank you!


When I face C# and Java I choose Java.
Nitzan Levi
Greenhorn

Joined: Feb 19, 2003
Posts: 22
hi,
yes there is a class(or classes) that implements those interfaces, but you'r not suppose to see them. this classes are implemented by the web container provider and you'r using those classes by activating the interfaces.
hope it helps !


nitzan levi :-)
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi nitzan levi !
You means it have been instanced by the servlet container?!It equals that the HttpServletResponse is a class in servlet container but not a interface?! :roll:
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

What it means is that the class implements the interface. We know nothing about the class except it's declaration looks something like:
public class VendorSpecificHTTPResponse implements javax.servlet.http.HttpServletResponse{

This means that the class is garunteed to implement the getWriter() method.
When the response is created by the server, there would be some code like:

But, since we are not concerned with the details of how the server actaully works, we never see this code and, in fact, cannot even see the VendorSpecificHTTPResponse class.
(If you were interested to know what class you were actually using, you could do:
response.getClass().getName()
and I garuntee you that the result will not be javax.servlet.http.HttpServletResponse)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi Joel McNary!
Thank you for answering my question!I understand you means and you are right!That class is hided by servlet container that implements it!Thank you again!
 
 
subject: Why this request method can be used in this way?!