views:

2819

answers:

2

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?

A: 

I've not solved the strange behaviour above, but I have managed to find an error in the url rewriting, pages where not being redirected to 'mySearch.action' but to 'mySearch.action?'. Using url rewriting now with a fixed rule and not including query params seems to work fine.

EDIT: I eventually traced this to a problem with urlrewritefilter being set up to listen on both REQUEST and FORWARD. Apparently this causes GET parameters to get parsed twice. I however still don't include query params (as that usually confuses things anyway), so this might not fix the problem completely. It's the most likely culprit though.

In particular, my filter mapping now looks like:

<filter-mapping>
     <filter-name>UrlRewriteFilter</filter-name>
     <url-pattern>/*</url-pattern>
     <dispatcher>REQUEST</dispatcher>
</filter-mapping>
wds
accepted own answer so it doesn't show up as unanswered
wds
A: 

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...

pierdeux
I was sorta aware, I thought you needed to set the extension to empty in the config though. But in our case this didn't really solve it as we're redirecting all types of rest-like urls that don't always correspond to different actions. Thanks though.
wds