aspose file tools*
The moose likes Struts and the fly likes Struts 2  - Action name works with any URL pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2  - Action name works with any URL pattern" Watch "Struts 2  - Action name works with any URL pattern" New topic
Author

Struts 2 - Action name works with any URL pattern

Brient Oh
Greenhorn

Joined: Oct 23, 2009
Posts: 1
Hi,

I'm trying to work on Struts 2 and stuck in the very beginning....

I'm using Strtus 2.1.6. Here is my struts.xml



I deployed my application on the Tomcat 6 and tested the following URLs;

http://localhost:8080/HelloWorld
http://localhost:8080/mypackage/HelloWorld
http://localhost:8080/foobar/HelloWorld
http://localhost:8080/foobar/HelloWorld.action

All of them work fine.... I means... they are all display /hello.jsp page.
I expected that only the first link would work; the others would be 404 error...

Even, this URL, http://localhost:8080/12312312oijwoie/HelloWorld, works!!
I think any URL pattern is working as long as the action name is matching at the end.

Any comments and solution would be very appreciated.

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9311
    
  17

I think this is working because of the namespace="/" part. If you read the namespace-configuration it says

A root namespace ("/") is also supported. The root is the namespace when a request directly under the context path is received. As with other namespaces, it will fall back to the default ("") namespace if a local action is not found.

So its acting like a fallback, when you write /foobar/HelloWorld, struts tries to find a HelloWorld action in foobar namespace, since none is found, so the request is sent to the HelloWorld in default namespace...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

But there isn't a HelloWorld action in the default namespace.

Are you deploying the Convention plugin?

You might want to deploy the config-browser plugin to see what Struts 2 thinks your configuration space looks like.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 - Action name works with any URL pattern