Java – Combining UrlRewriteFilter and struts 2 with get parameters

jakarta-eejavamodel-drivenstruts2url-rewriting

Following up on an older question of mine, I managed to get URL Rewriting working somewhat correctly for my struts project where URLs like search?q=blah get converted to queries search.action?q=blah. We use UrlRewriteFilter for this. This seems to forward fine to struts (if making sure it has a filter mapping with FORWARD), but when the ParametersIntercepter runs it seems to be catching every parameter twice, and adding comma's in between. So the following:

search.action?q=blah

Sets the parameter q on the Criteria object (see further) to:

[ blah, blah ]

The parameters are set using ModelDriven<Criteria> Where Criteria is a simple class with a bunch of properties to be set from the GET string.

I'm at a loss to explain why this is happening. Has anyone ever seen anything like this? Am I doing something wrong with regards to the filters/interceptors?

edit: It seems the ParametersInterceptor simply sets the parameters contained inside the ActionContext object. I'm not sure (and am not seeing any debug messages that indicate) where these values are being set in the ActionContext. Does anyone care to clarify how this is all supposed to work?

Best Answer

Just in case you might still be interested in an extra piece of info, are you aware that the most recent versions of Struts2 (that is, 2.1.?) do not impose the extension .action to your actions? In fact, you do not need any extension at all!

If my recollection serves me right, the only requirement is that, in web.xml, you map your Struts2 filter (org.apache.struts2.dispatcher.FilterDispatcher) to url-pattern: /*

<filter-mapping>
   <filter-name>action2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

From then on, a <s:url> tag appearing on a page whose extension is empty will, in turn, generate a url with no extension...

Related Topic