• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chaining filter servlet

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I all
I need to log all post parameter inside a db table. I create for this a Filter Servlet with jsp mapping. The problem is that this servlet is called after the Action class tha handle the post action.

Inside Filter Servlet, when I use the code
Enumeration enumPostData = httpRequest.getParameterNames();
..
Enumeration is empty, because Action class forward the request using the parameter "redirect=true".

This is part of struts-config:
<action name="autocarro000" type="it.genialloyd.autocarro.ProcessaAutocarro000" validate="false" input="/autocarro/autocarro000.jsp" scope="session" path="/processaAutocarro000">
<forward name="autocarro040" path="/do/preparaAutocarro040" redirect="true" />

This is web.xml:

<filter>
<filter-name>statistichePagina</filter-name>
<filter-class>it.genialloyd.statistiche.ServletStatPagina</filter-class>
</filter>
<filter-mapping>
<filter-name>statistichePagina</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<listener>
<listener-class>it.genialloyd.statistiche.ServletStatSessione</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml,/WEB-INF/struts-infortuni.xml,/WEB-INF/struts-autocarro.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>4</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

Is it possible to invoke Filter class (statistichePagina) before the ActionServlet of struts?
Thanks
Thanks
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of making the filter intercept the request before it goes to a jsp, you could map the filter to intercept all requests to the action servlet. In this way it will be called before the action servlet and action classes.


Note however that when you do action-action forwarding you will probably be logging the same post parameters again. Just check if that happens, I suppose it should, not sure though.

Also ensure that the filter is only a pre-processing filter and not a post-processing filter, otherwise you might face errors when forwarding requests to another action.

Sheldon Fernandes
 
reply
    Bookmark Topic Watch Topic
  • New Topic