Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Request in filter  RSS feed

 
Amreek Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we implements filter interface in servlet than we must pass three parameter in its dofilter() method like this:
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
{
//implementation
}

why we cannot use HttpServletRequest and HttpServletRespone in place of ServletRequest and ServletResponse like this:

public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
{
//implementation
}

why we can not use HttpServletRequest and HtpServletResponse in the place of ServetRequest and ServletResponse?
if not than tell me why we can use both(HttpServletRequest or ServletRequest) in servlet while we implement its doget() or doPost() method?
 
Tim Cooke
Marshal
Posts: 3632
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you haven't actually tried this?

Have a go at passing HttpServletRequest and HttpServletResponse objects into the servlet method, see what happens, then come back to us.
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface Filter is in the package javax.servlet, referring stuff in the same package, whereas HttpServlet is in the package javax.servlet.http.
The API does not restrict the usage of Filters to HttpServlets as opposed to plain Servlets.

However HttpServletRequest extends the ServletRequest interface to provide request information for HTTP servlets.
So a HttpServletRequest is a ServletRequest.
 
Tim Cooke
Marshal
Posts: 3632
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is very similar to your other question where the relationship between a ServletRequest and a HttpServletRequest was explained. Did you understand that OK?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!