File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HttpServletRequest / HttpServletResponse.......puzzled!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest / HttpServletResponse.......puzzled!!!" Watch "HttpServletRequest / HttpServletResponse.......puzzled!!!" New topic

HttpServletRequest / HttpServletResponse.......puzzled!!!

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am new to servlets and as such facing impediments in my understanding of the every step. But I am determined to get over it.
Here goes....HttpServletRequest and HttpServletResponse are interfaces and we are required to pass these objects while
calling a servlet. I do not understand how interfaces can be used without they being implemented in the first place.
This is an SOS.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has a naming policy, described here and "rajendra" is not a valid name. Please choose one which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
This is a fairly common question, and not just about Servlets. An interface specifies the methods which a class must have if it implements that interface. An interface mey be implemented by as many classes as you like.
In the particular case of HttpServletRequest and HttpServletResponse these two interfaces are implemented inside the servlet container. When a servlet container invokes the service(), doPost(), doGet() (etc.) methods, it first creates an instance of one of its classes, which happens to implement the HttpServletRequest interface, and then passes that class to your servlet. HttpServletResponse is similar.
For a full example of how this is done, get the source code for any servlet container or servlet-capable webserver, and 'find files' or 'grep' for any java files containing the string 'implements HttpServletRequest'.
Rajendra Deshpande
Ranch Hand

Joined: Nov 24, 2000
Posts: 40
Frank Carver,
Thank you for the quick reply.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
And thank you for changing your name so promptly.
I agree. Here's the link:
subject: HttpServletRequest / HttpServletResponse.......puzzled!!!
It's not a secret anymore!