4

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 ?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
never
  • 671
  • 1
  • 6
  • 18
  • Because it thinks you are trying to get an action with extension .lastname, you need to write a rule for that – Denees Feb 27 '14 at 12:27
  • Did you try giving it in quotes.
    like //somehost:8080/myapp/auth/'firstname.lastname '
    not sure though...
    – Prakash Feb 27 '14 at 12:24

1 Answers1

3

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

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • 1
    @never: @AndreaLigios: Empty value isn't best for the `struts.action.extension`. See http://stackoverflow.com/q/12607075/1700321. – Aleksandr M Feb 27 '14 at 21:07
  • An empty setting wont work for his/her use case though. The other alternative would be to use a custom `ActionMapper`. – Steven Benitez Feb 28 '14 at 03:28
  • @AleksandrM Woah, september 2012... I missed that, +1. So if I got that right, `""` means EVERYTHING (including static res), while `","` means only actions with no extensions (*and* static resources without extension, not standard but can happen); adding `","` will not work then for this use-case, because `.lastname` will be threated as an action extension, and filtered (as @StevenBenitez pointed out). Then, unless using a custom ActionMapper, the only shot for OP question is to use `""` and avoid using struts2 to serve static resources... is this right ? – Andrea Ligios Feb 28 '14 at 09:30