You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tauri Valor <su...@gmail.com> on 2008/03/13 05:05:00 UTC
Struts2 URL problem
Hi
I have the following problem with url in my web application:
I run my app using Struts2 and Tomcat6.
Context name of webapp: MY_WEB
Namespace in my package tag of struts-config.xml:
package name="register" namespace="/register" extends="tiles-default"
Mapping of Action class in my struts-config.xml :
action name= acc.register.RegistrationForm
A Href link in my jsp page:
a href="register/acc.register.RegistrationForm.do"
Now, the following url works fine when I launch my app:
http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
But the problem is the url when added something between my
packagename(register)and my uri (acc.register.RegistrationForm.do) like
following:
http://localhost:8080/MY_WEB/register/somecrap/acc.register.RegistrationForm.do
it still works fine instead of displaying the error page. I need to get an
error page if I give wrong url like the above.
What is my mistake ?
Pls advise.
--
View this message in context: http://www.nabble.com/Struts2-URL-problem-tp16020941p16020941.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Tauri Valor <su...@gmail.com>.
Thanks Jeromy
I will try your approach and let you know.
Jeromy Evans - Blue Sky Minds wrote:
>
> At this point I'd either
> a) accept it, because it's unlikely to cause really problems or ever be
> noticed by a real user. It's just scrappy
> b) create a custom ActionMapper derived from the default one that
> removes that feature
> c) Use a plugin that does b for you
>
> I don't use the DefaultActionMapper myself any more.
>
> Option b is not as difficult as it may first seem. The default code is
> quite straight-forward [1], [2]
>
> As you're using Struts 2.0 you can't use the new Convention plugin. As
> you're using struts.xml rather than CodeBehind I don't recommend
> switching to the SmartURLs plugin as you'll have to re-check all the
> configuration (unless it's a small application) [3]. The
> Struts2UrlPlugin [4] will fix the problem immediately by dropping the
> jar into the classpath but it's not released yet, undocumented and is
> probably overkill.
>
> So I recommend a) or b).
>
> [1] http://struts.apache.org/2.x/docs/actionmapper.html
> [2]
> http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?view=markup
> [3] http://cwiki.apache.org/S2PLUGINS/smarturls-plugin.html
> [4] http://code.google.com/p/struts2urlplugin/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts2-URL-problem-tp16020941p16089143.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
At this point I'd either
a) accept it, because it's unlikely to cause really problems or ever be
noticed by a real user. It's just scrappy
b) create a custom ActionMapper derived from the default one that
removes that feature
c) Use a plugin that does b for you
I don't use the DefaultActionMapper myself any more.
Option b is not as difficult as it may first seem. The default code is
quite straight-forward [1], [2]
As you're using Struts 2.0 you can't use the new Convention plugin. As
you're using struts.xml rather than CodeBehind I don't recommend
switching to the SmartURLs plugin as you'll have to re-check all the
configuration (unless it's a small application) [3]. The
Struts2UrlPlugin [4] will fix the problem immediately by dropping the
jar into the classpath but it's not released yet, undocumented and is
probably overkill.
So I recommend a) or b).
[1] http://struts.apache.org/2.x/docs/actionmapper.html
[2]
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?view=markup
[3] http://cwiki.apache.org/S2PLUGINS/smarturls-plugin.html
[4] http://code.google.com/p/struts2urlplugin/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
> hi all
>
> if i want to create the url something like this, and withour .do or .action,
> like REST
>
>
URLs without the extension is possible by setting the property:
struts.action.extension=action,,
Where the double comma indicates "no extension".
> is smartURL the answer or we must use RESTplugins, which we know we cannot
> mixed REST with current struts2 setting
>
> i want the url like this http://localhost:8080/cimande/profile/fthamura
>
> which fthamura is my account
>
>
Passing parameters through the path is supported by the
NamedVariablePatternMatcher, a largely undocumented feature of XWork2.1
(search the user mail archives for discussion), or by the
Struts2UrlPlugin which is not released and also undocumented
(http://code.google.com/p/struts2urlplugin/). I created the latter
specifically for this use-case and because it's impossible for the
NamedVariablePatternMatcher to solve all the issues in isolation. It
won't be released or announced until I have time to write a user guide
though.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Frans Thamura <fr...@meruvian.org>.
hi all
if i want to create the url something like this, and withour .do or .action,
like REST
is smartURL the answer or we must use RESTplugins, which we know we cannot
mixed REST with current struts2 setting
i want the url like this http://localhost:8080/cimande/profile/fthamura
which fthamura is my account
F
Re: Struts2 URL problem
Posted by Tauri Valor <su...@gmail.com>.
Thanks Jeromy!
I tried all the four solutions that youve provided..but I still have the
same problem. :)
Im still unable to get the error page for the wrong url with the scrappy
namespace in the addressbar.
If you have thought of any other solution pls let me know. I will try and
let you know..
Thanks again for your time..
Thanks,
Tauri.
Jeromy Evans - Blue Sky Minds wrote:
>
> Hi Tauri,
>
> I don't have time to try it myself right now, but what I meant was
> create an additional default package that contains no actions. I'm not
> sure if it will help though. The idea is that when the default action
> mapper can't match the namespace, it falls back to an empty back.
>
> Like this:
>
> <package name="default" namespace="" extends="struts-default"></package>
> <package name="register" namespace="/register" extends="tiles-default">
> ...normal actions...
> </package>
>
>
> ie. create an empty back in the "" namespace. If that doesn't work also
> try the "/" namespace.
>
> If that doesn't work, there's also some poorly documented options for
> the default ActionMapper.
> Try setting the struts property
> "struts.mapper.alwaysSelectFullNamespace" to true. It may be the one
> you need. Put it in struts.properties or a const in struts.xml.
>
> Hope that helps,
> Jeromy Evans
>
> Tauri Valor wrote:
>> Thanks Jeromy!
>>
>> Ive tried creating a package with empty name space ie :
>>
>> <package name="register" namespace="/" extends="tiles-default">
>>
>> then the following url :
>>
>> http://localhost:8080/MY_WEB/acc.register.RegistrationForm.do
>>
>> without the namespace works fine ..
>>
>> But any other way to keep my namespace in tact in the url because the
>> above
>> may not be acceptable?
>>
>> Thanks,
>> Tauri
>>
>>
>>
>>
>> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Jeromy Evans - Blue Sky Minds wrote:
>>
>>> No mistake. AFAIK that's a design flaw of the default action mapper.
>>>
>>> See:
>>> http://www.planetstruts.org/struts2-blank/example/somecrap/HelloWorld.action
>>>
>>> If there's no match in a package namespace it falls back to the default
>>> package and matches a little to generously.
>>>
>>> You may be able to avoid it by creating a package with an empty
>>> namespace containing no actions. Not sure about that one...
>>>
>>> Tauri Valor wrote:
>>>
>>>> Hi
>>>>
>>>> I have the following problem with url in my web application:
>>>>
>>>> I run my app using Struts2 and Tomcat6.
>>>>
>>>> Context name of webapp: MY_WEB
>>>>
>>>> Namespace in my package tag of struts-config.xml:
>>>>
>>>> package name="register" namespace="/register" extends="tiles-default"
>>>>
>>>>
>>>> Mapping of Action class in my struts-config.xml :
>>>>
>>>> action name= acc.register.RegistrationForm
>>>>
>>>>
>>>> A Href link in my jsp page:
>>>>
>>>>
>>>> a href="register/acc.register.RegistrationForm.do"
>>>>
>>>>
>>>>
>>>> Now, the following url works fine when I launch my app:
>>>>
>>>> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>>>>
>>>>
>>>> But the problem is the url when added something between my
>>>> packagename(register)and my uri (acc.register.RegistrationForm.do) like
>>>> following:
>>>>
>>>> http://localhost:8080/MY_WEB/register/somecrap/acc.register.RegistrationForm.do
>>>>
>>>> it still works fine instead of displaying the error page. I need to get
>>>> an
>>>> error page if I give wrong url like the above.
>>>>
>>>> What is my mistake ?
>>>>
>>>> Pls advise.
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts2-URL-problem-tp16020941p16087758.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Hi Tauri,
I don't have time to try it myself right now, but what I meant was
create an additional default package that contains no actions. I'm not
sure if it will help though. The idea is that when the default action
mapper can't match the namespace, it falls back to an empty back.
Like this:
<package name="default" namespace="" extends="struts-default"></package>
<package name="register" namespace="/register" extends="tiles-default">
...normal actions...
</package>
ie. create an empty back in the "" namespace. If that doesn't work also
try the "/" namespace.
If that doesn't work, there's also some poorly documented options for
the default ActionMapper.
Try setting the struts property
"struts.mapper.alwaysSelectFullNamespace" to true. It may be the one
you need. Put it in struts.properties or a const in struts.xml.
Hope that helps,
Jeromy Evans
Tauri Valor wrote:
> Thanks Jeromy!
>
> Ive tried creating a package with empty name space ie :
>
> <package name="register" namespace="/" extends="tiles-default">
>
> then the following url :
>
> http://localhost:8080/MY_WEB/acc.register.RegistrationForm.do
>
> without the namespace works fine ..
>
> But any other way to keep my namespace in tact in the url because the above
> may not be acceptable?
>
> Thanks,
> Tauri
>
>
>
>
> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>
>
>
>
>
>
>
>
>
> Jeromy Evans - Blue Sky Minds wrote:
>
>> No mistake. AFAIK that's a design flaw of the default action mapper.
>>
>> See:
>> http://www.planetstruts.org/struts2-blank/example/somecrap/HelloWorld.action
>>
>> If there's no match in a package namespace it falls back to the default
>> package and matches a little to generously.
>>
>> You may be able to avoid it by creating a package with an empty
>> namespace containing no actions. Not sure about that one...
>>
>> Tauri Valor wrote:
>>
>>> Hi
>>>
>>> I have the following problem with url in my web application:
>>>
>>> I run my app using Struts2 and Tomcat6.
>>>
>>> Context name of webapp: MY_WEB
>>>
>>> Namespace in my package tag of struts-config.xml:
>>>
>>> package name="register" namespace="/register" extends="tiles-default"
>>>
>>>
>>> Mapping of Action class in my struts-config.xml :
>>>
>>> action name= acc.register.RegistrationForm
>>>
>>>
>>> A Href link in my jsp page:
>>>
>>>
>>> a href="register/acc.register.RegistrationForm.do"
>>>
>>>
>>>
>>> Now, the following url works fine when I launch my app:
>>>
>>> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>>>
>>>
>>> But the problem is the url when added something between my
>>> packagename(register)and my uri (acc.register.RegistrationForm.do) like
>>> following:
>>>
>>> http://localhost:8080/MY_WEB/register/somecrap/acc.register.RegistrationForm.do
>>>
>>> it still works fine instead of displaying the error page. I need to get
>>> an
>>> error page if I give wrong url like the above.
>>>
>>> What is my mistake ?
>>>
>>> Pls advise.
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Tauri Valor <su...@gmail.com>.
Thanks Jeromy!
Ive tried creating a package with empty name space ie :
<package name="register" namespace="/" extends="tiles-default">
then the following url :
http://localhost:8080/MY_WEB/acc.register.RegistrationForm.do
without the namespace works fine ..
But any other way to keep my namespace in tact in the url because the above
may not be acceptable?
Thanks,
Tauri
http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
Jeromy Evans - Blue Sky Minds wrote:
>
> No mistake. AFAIK that's a design flaw of the default action mapper.
>
> See:
> http://www.planetstruts.org/struts2-blank/example/somecrap/HelloWorld.action
>
> If there's no match in a package namespace it falls back to the default
> package and matches a little to generously.
>
> You may be able to avoid it by creating a package with an empty
> namespace containing no actions. Not sure about that one...
>
> Tauri Valor wrote:
>> Hi
>>
>> I have the following problem with url in my web application:
>>
>> I run my app using Struts2 and Tomcat6.
>>
>> Context name of webapp: MY_WEB
>>
>> Namespace in my package tag of struts-config.xml:
>>
>> package name="register" namespace="/register" extends="tiles-default"
>>
>>
>> Mapping of Action class in my struts-config.xml :
>>
>> action name= acc.register.RegistrationForm
>>
>>
>> A Href link in my jsp page:
>>
>>
>> a href="register/acc.register.RegistrationForm.do"
>>
>>
>>
>> Now, the following url works fine when I launch my app:
>>
>> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>>
>>
>> But the problem is the url when added something between my
>> packagename(register)and my uri (acc.register.RegistrationForm.do) like
>> following:
>>
>> http://localhost:8080/MY_WEB/register/somecrap/acc.register.RegistrationForm.do
>>
>> it still works fine instead of displaying the error page. I need to get
>> an
>> error page if I give wrong url like the above.
>>
>> What is my mistake ?
>>
>> Pls advise.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Struts2-URL-problem-tp16020941p16021626.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2 URL problem
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
No mistake. AFAIK that's a design flaw of the default action mapper.
See:
http://www.planetstruts.org/struts2-blank/example/somecrap/HelloWorld.action
If there's no match in a package namespace it falls back to the default
package and matches a little to generously.
You may be able to avoid it by creating a package with an empty
namespace containing no actions. Not sure about that one...
Tauri Valor wrote:
> Hi
>
> I have the following problem with url in my web application:
>
> I run my app using Struts2 and Tomcat6.
>
> Context name of webapp: MY_WEB
>
> Namespace in my package tag of struts-config.xml:
>
> package name="register" namespace="/register" extends="tiles-default"
>
>
> Mapping of Action class in my struts-config.xml :
>
> action name= acc.register.RegistrationForm
>
>
> A Href link in my jsp page:
>
>
> a href="register/acc.register.RegistrationForm.do"
>
>
>
> Now, the following url works fine when I launch my app:
>
> http://localhost:8080/MY_WEB/register/acc.register.RegistrationForm.do
>
>
> But the problem is the url when added something between my
> packagename(register)and my uri (acc.register.RegistrationForm.do) like
> following:
>
> http://localhost:8080/MY_WEB/register/somecrap/acc.register.RegistrationForm.do
>
> it still works fine instead of displaying the error page. I need to get an
> error page if I give wrong url like the above.
>
> What is my mistake ?
>
> Pls advise.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org