Ilya
Ilya

Reputation: 211

Struts2 seo-friendly url?

Instead of

Users.action?login=foo

I want to have

/users/foo/

In spring mvc they have "URI templates" for it, but they are only annotation-based. Is it possible to do such url-s in Struts with xml from-the-box?

The only one thing I found was external tool: http://www.progbear.com/voice/2010/struts-2-create-friendly-url-with-urlrewritefilter

wildcards in struts do not work with "/" and cannot pass parameters to action.

Sure I can get this info from request but I believe Struts should support it.

Upvotes: 0

Views: 2268

Answers (1)

Steven Benitez
Steven Benitez

Reputation: 11055

Yes, you can do this out-of-the-box with Struts2. Check out the NamedVariablePatternMatcher, which I described here.

In your case, you would need to enable the options in the answer that I linked to above and then map your action as:

<action name="users/{login}" class="...">
    ...
</action>

You could also look into the rest plug-in.

Upvotes: 1

Related Questions