javaregexurl-rewritingstruts2tuckey-urlrewrite-filter

How to use &amp in tuckey outbound rules in Struts 2


I'm having trouble with Tuckey URL outbound rules. We are using Tuckey with Struts2.

Outbound rule:

<outbound-rule>
    <from>^/articleList\?category=(\d*)&amp;page=(\d*)(;jsessionid=.*)?$</from>
    <to last="true">/list/$1/$2</to>
</outbound-rule>

JSP:

<a href="<s:url value="/articleList" ><s:param name="category"
value="#article.category" /><s:param name="page" value="1" /></s:url>"    target="_blank[articlelist]</a>

Although it says processing outbound rule it's not forwarding to my URL. In the url-rewritestatus it shows all my rules but doesn't show matched ones. debug log:

org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing outbound url for /articleList?category=3&amp;page=1
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Outbound Rule 0 run called with /articleList?category=3&amp;page=1
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Outbound Rule 1 run called with /articleList?category=3&amp;page=1
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Outbound Rule 2 run called with /articleList?category=3&amp;page=1
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Outbound Rule 3 run called with /articleList?category=3&amp;page=1
org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Outbound Rule 4 run called with /articleList?category=3&amp;page=1

debuging the source I see

url:/articleList?category=1&amp;page=1
pattern:^/articleList\?category=(\d*)&page=(\d*)(;jsessionid=.*)?$

What I am doing wrong?

evn:struts2 + spring3 jetty


Solution

  • You have escaped & symbol in the url and you see in the source code it's &amp;. This doesn't allow the pattern to match the url. Try to change the pattern to match both escaped and unescaped ampersand.

    <from>^/articleList\?category=(\d*)(\&|&amp;){1}page=(\d*)(;jsessionid=.*)?$</from>