File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How can we access the methods in the HttpServletRespone interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can we access the methods in the HttpServletRespone interface" Watch "How can we access the methods in the HttpServletRespone interface" New topic
Author

How can we access the methods in the HttpServletRespone interface

Suresh Khanna
Greenhorn

Joined: Jan 04, 2004
Posts: 16
Hi Guys,
How can we access the methods in the HttpServletRespone interface
object without implementing this interface.
ie we are using
public void doGet(HttpServletRequest req, HttpservletRespone res)
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
---------
---------
}

where the setrContentType() and getWriter() method implementations are done. Pls Clarify.
Thank in advance
Suresh K
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30377
    
150

Suresh,
doGet() is passed a class that implements the HttpServletResponse interface. Each servlet container provides its own implementation. You just call the methods as shown in your example.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dinesh Kumar
Ranch Hand

Joined: Jul 03, 2002
Posts: 54
Suresh,
To give a more elaborate reply, the HttpServletResponse res object that is being passed as a parameter actually is an object of a class that implements the HttpServletResponse interface.
You'll find that most of the time it's the interface that you're using during your Servlet programming. This is because the Servlet specs. doesn't manadate any class names for most of the interfaces. That's left upto the Servlet containers (e.g. tomcat) to design.
So if you try something like, System.out.println(res.getClass()) on your response object, you'll find the class name that the container is actually using.
Since this class implements the interface HttpServletResponse, it is perfectly legal to declare your res object to be of the type HttpServletResponse.
Same is the case with many other interfaces in the Servlet API.
Hope that helps.
Suresh Khanna
Greenhorn

Joined: Jan 04, 2004
Posts: 16
Hi,
Thank you Jeanne and Dinesh for your answers.
Dinesh, got the class that is implementing the HttpServletResponse interface
by calling getClass() method. I appreciate your elaborate explanation.

Regards
Suresh K
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we access the methods in the HttpServletRespone interface