Is it possible for a servlet filter to work out which servlet will handle the request?

You might want to setup servlet filter mapping to not fire it in case of requests for particular servlet altogether.

You might want to setup servlet filter mapping to not fire it in case of requests for particular servlet altogether. Example configuration could look like this assuming that there is one DefaultServlet that should not be impacted by filter and two other servlets FirstServlet and SecondServlet which have to be affected. MyFilter FirstServlet MyFilter SecondServlet.

Unfortunately, the servlet I want to ignore is the default servlet which handles all URLs not handled elsewhere. This means it would have a very complex URL pattern. – tomdee Apr 4 at 10:03 You could map filters not only to URL patterns but to particular servlets as well.

This means you could define mapping only for servlets for which you want to have filter applied. – Oleg Iavorskyi Apr 4 at 10:06.

You can assign url pattern which are to be filtered e.g. Admin com.nil.FilterDemo. AdminFilter Admin /admin/* This filter will run for every single request handled by the servlet engine with /admin mapping.

He wants to do the inverse. – BalusC Apr 4 at 13:31.

I always think that you should be able to make exceptions to url-patterns in a web. Xml e.g. If you could do something like this: MyFilter /resources/* /resouces/images/blah. Jpg but you can't so that's no help to you!

You obviously have access to the URL in the Filter through the request object so you could do something like this: public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)sRequest; if(!request.getRequestURI. Equals("/resources/images/blah. Jpg")) { doLogging(); } chain.doFilter(); } (hard-coded here but you'd probably read it from a property file) although this may not be of use to you as you mentioned servlets in your query as opposed to URL patterns.

EDIT: another thought. If you don't mind doing your logging after the servlet has completed you could do something like this: public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException { sRequest. SetAttribute("DO_LOGGING", new Boolean(true)); chain.doFilter(); Boolean doLogging = (Boolean)sRequest.

GetAttribute("DO_LOGGING"); if(doLogging) { doLogging(); } } and your servlet that you want to exclude from logging can just set that attribute to false. Public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { req. SetAttribute("DO_LOGGING", new Boolean(false)); // other stuff }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions