0

In my application I am using Struts, I have introduced a filter in web.xml to check any malicious character available in request or not before it reaches to corresponding action or .do . If any malicious character available I need to redirect to error page and if not, I want to allow the request to corresponding action or .do. How can I forward the request to original request after filter check?

   <filter>
      <filter-name>MaliciousFilter</filter-name>
      <filter-class>com.MaliciousFilter</filter-class>
   </filter>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Mansrad
  • 1
  • 2

1 Answers1

0

Just invoke

chain.doFilter(request, response);

and you will pass request back down the filter chain. If you don't have more filters the original action will be called.

  • Thanks for the info. Let me try with it. – Mansrad Jul 20 '16 at 10:18
  • It is working but I have some other problem. When I try to getParts. It is coming empty for multipart/form-data. I can get getParts only in HttpServletRequest. But I am not able to access HttpServletRequest inside doFilter. Even though I type cast from servletRequest to HttpServletRequest . I am getting empty value for getParts. Can you please help me how to resolve? (final Part part : ((HttpServletRequest) servletRequest).getParts()) – Mansrad Jul 21 '16 at 10:12
  • is there a way to access HttpServletRequest inside doFilter without type casting from ServletRequest. Because if type caste, I will get getParts as empty value. – Mansrad Jul 21 '16 at 10:26
  • It isn't a casting problem...What Server are you using? Maybe you find this useful http://stackoverflow.com/questions/8047173/how-to-enable-multipart-form-data-in-tomcat-7-0-8-server – Marco A. Hernandez Jul 21 '16 at 12:22
  • I am using Tomcat server. When I invoke doFilter method, doFilter (ServletRequest servletRequest, ServletResponse servletResponse,FilterChain filterChain) I can't use getParts() in doFilter(). getParts() is available in HttpServletRequest. Even though I type cast to HttpServletRequest, I get null value. Is there any way to access HttpServletRequest inside doFilter without type caste from servletRequest? or how Can I directly access HttpServletRequest inside doFilter without passing it into the method? Error Snippet for(final Part part : ((HttpServletRequest) servletRequest).getParts()) – Mansrad Jul 21 '16 at 14:04
  • Did you set allowCasualMultipartParsing="true" in the webapp as @BalusC suggest in his post? – Marco A. Hernandez Jul 22 '16 at 10:17
  • I have tried but I facing issue while accessing it. When I put allowCasualMultipartParsing="true" in context.xml. It checks multi part for every request. So if it content type null or text/html, I am getting exceptions. Is there way to enable if request is only multipart/form-data – Mansrad Jul 22 '16 at 11:58