Struts2 better URLs with dot inside

2019-06-24 20:49发布

问题:

Let's say we need to get a login form with pre-defined username.

So if user goes to url:

//somehost:8080/myapp/auth/myusername

the action should take myusername as input parameter.

I tried http://www.struts2.info/blog/better-urls-with-struts2 as example, and it works great.

But if myusername contains dots, like:

//somehost:8080/myapp/auth/firstname.lastname 

, I get 404 error.

Is there any simple solution to use dots as a part of url parameter ?

回答1:

In struts.xml:

<constant name="struts.action.extension" value=""  />

and in web.xml:

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

Untested, but it should work