Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Nitzan Levi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic