Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would javax.servlet.Filter.doFilter(ServletRequest req, ServletResponse res) be called with anything other than HttpServletRequest/Response?

Tags:

java

servlets

I've been writing servlets and filters for years and it is something that has always irked me a little - the checking and casting of ServletRequest and ServletResponse parameters to HttpServletRequest and HttpServletResponse, particularly with filters as there is no standard HttpFilter base class to do this for you - unlike servlets.

The question is - when would you ever see anything other that HttpServletRequest/HttpServletResponse being passed to your servlet/filter and what should you do if you do?

like image 247
pillingworth Avatar asked Sep 10 '12 10:09

pillingworth


People also ask

What is doFilter () method in Java?

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

What is the purpose of javax servlet filter?

Java Servlet Filter is used to intercept the client request and do some pre-processing. It can also intercept the response and do post-processing before sending to the client in web application.

What is servlet and servlet filter Why do we need servlet filters?

A filter is an object that is invoked at the preprocessing and postprocessing of a request. It is mainly used to perform filtering tasks such as conversion, logging, compression, encryption and decryption, input validation etc. The servlet filter is pluggable, i.e. its entry is defined in the web.


1 Answers

In some yet-to-be-realized world where there are other servlet types besides HttpServlets.

like image 197
user207421 Avatar answered Sep 19 '22 06:09

user207421