Apache Struts 2 Documentation > Home > FAQs > Why are request parameters appended to our hyperlinks |

Apache Struts 2 Documentation
Why are request parameters appended to our hyperlinks
Edit Page Browse Space Add Page Add News
Added by Ted Husted, last edited by Ted Husted on Jul 26, 2006

We're trying to change the locale using the <url> tag, but after using the link, they all have an extra request parameter appended. A link that reads on the first display `Welcome.do?request_locale=en`, after being used reads `Welcome.do?request_locale=en&request_locale=en"`.

Here's the code we're using:

Doesn't work right!

    <ul>
       <li><a href="<s:url action="Welcome?request_locale=en"/>">English</a></li>
       <li><a href="<s:url action="Welcome?request_locale=ja"/>">Japanese</a></li>
       <li><a href="<s:url action="Welcome?request_locale=ru"/>">Russian</a></li>
    </ul>

The URL tag isn't meant to be used with a query string. The best way to write this would be:

Use the param tag instead

    <s:url action="Welcome">
     <s:param name="request_locale" value="en" />
    </s:url>

The reason is the url tag has this "includeParams" tag, which can automatically include all the query string parameters in the URL. The default value is GET, meaning all the GET parameters will be automatically included in the final URL, which is what we see here.