as you can see above, I need to alter the request parameters with the results of getParameterValues(String) from the RequestWrapper class. I was told the getParameterValues(String) method would automatically be invoked when chain.doFilter() is called, but it seems untrue. Is there any way I can alter the request parameter values received by the servlet in any way? Making a request attribute doesn't seem to be the best solution. Thanks!
I am using Struts, creating a request attribute would create so much work for me and would therefore render this feature(of setting of bean properties automatically) useless. There must be another way...
I already did this, here...
I still can't trim or replace the characters I need to filter. Thank you very much for your answers they were very helpful.
The getParameterValues method isn't automatically going to be invoked in the filter but it doesn't need to. Since your passing your wrapper to the doChain method, any servlets or JSPs that receive that requestWrapper will use it's getParameterValues instead of the one in the original request.
Ben, the problem is that the getParameterValues() method is not invoked in my ActionServlet at all... In my Action servlet, the execute method still has the HttpServletRequest as the argument for request. Is that ok? If that's ok, I'm not using the HttpServletRequest implicitly in my execute method since this is automatically done for my by struts. So what I do is...
so, after struts did all the dirty work, I could use the bean method like this...
the latter should get the firstName parameter(the trimmed one), however, it doesn't... What do you think is the problem? Thanks a lot, I hope I could hear more answers. [ July 26, 2006: Message edited by: Timothy Sam ]
Joined: Aug 17, 2005
By using debug statements in your filter have you established if it is being called? (simple System.out.println(..) statements will write to /logs/catalina.out in tomcat).
I'm not familiar with struts configuration, but it seems as though your filter is not being used.
As an aside - if you are using this to clean invalid data from request parameters it is not a good solution. What happens if some user data actually requires the user to enter trailing whitespace or < > characters? You should be able to setup validation (within struts) on your user data to make sure it does not contain invalid characters. Also make sure you escape user data when displaying it back to the user; use of <c ut value="blah" /> will automatically escape html entities.
Joined: Sep 18, 2005
use of <cut value="blah" /> will automatically escape html entities.
Now that seems to be a better solution!
Well, I'm quite certain though that only the single servlet(.do) I mapped will be needing the filter.
I don't know yet if this problem is already solved or not... Got to try again later. Thanks!
Originally posted by Timothy Sam: Ben, the problem is that the getParameterValues() method is not invoked in my ActionServlet at all... In my Action servlet, the execute method still has the HttpServletRequest as the argument for request. Is that ok? If that's ok, I'm not using the HttpServletRequest implicitly in my execute method since this is automatically done for my by struts. So what I do is...
The filter, if invoked, should take care of that because it intercepts the request and replaces the servletRequest object with the wrapper object that you've created. When the struts class gets ahold of it IT will call the getParameterValues method.
You may also want to override getParameter to add some debug statements; just to make sure that Struts isn't using it instead of getParameterValues.