You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ralph Grove <ra...@gmail.com> on 2017/05/01 13:55:07 UTC
Re: Struts2 namespace confusion
On 2017-04-28 04:33 (-0400), Lukasz Lenart <lu...@apache.org> wrote:
> 2017-04-27 13:56 GMT+02:00 Ralph Grove <ra...@gmail.com>:
> > Matt, did this solve your problem? I'm having the same issue with namespaces. With this example, I can request ".../Home", ".../Home/Alpha", ".../Alpha/Alpha/Alpha", etc. The action executes in each case, but if the URL contains more than one slash, the relative path is messed up for files included in the JSP.
> >
> > Ralph Grove
> >
> > <!DOCTYPE struts PUBLIC
> > "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> > "http://struts.apache.org/dtds/struts-2.0.dtd">
> > <struts>
> >
> > <constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />
> > <constant name="struts.enable.SlashesInActionNames" value="false" />
> >
> > <package name="main" extends="struts-default">
> > <default-action-ref name="NotFound"/>
> >
> > <global-results>
> > <result name="error">/error.jsp</result>
> > </global-results>
> >
> > <global-exception-mappings>
> > <exception-mapping exception="java.lang.Exception" result="error"/>
> > </global-exception-mappings>
> >
> > <action name="NotFound">
> > <result>/error.jsp</result>
> > </action>
> >
> > <!-- Sidebar menu item and static link actions -->
> > <action name="Home" class="com.opensymphony.xwork2.ActionSupport">
> > <result>/WEB-INF/jsp/index.jsp</result>
> > </action>
> > <action name="Alpha" class="com.opensymphony.xwork2.ActionSupport">
> > <result>/WEB-INF/jsp/alpha.jsp</result>
> > </action>
> > <action name="Beta" class="com.opensymphony.xwork2.ActionSupport">
> > <result>/WEB-INF/jsp/beta.jsp</result>
> > </action>
> >
> >
> > <!-- Actions -->
> > <action name="AnAction" class="action.AnAction">
> > <result name="success">/WEB-INF/jsp/index.jsp</result>
> > <result name="input">/WEB-INF/jsp/beta.jsp</result>
> > </action>
> >
> > </package>
> > </struts>
>
> I assume you don't use the Convention plugin also what version do you use?
>
>
> Regards
> --
> \u0141ukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
Actually, your solution did work - I just forgot to define the root namespace. Here's my corrected struts.xml, which does treat extended URL's (e.g., .../Alpha/Alpha) as errors.
I'm using version 2.5.10.1 of the core library.
Ralph
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />
<constant name="struts.enable.SlashesInActionNames" value="false" />
<package name="default" extends="struts-default">
<default-action-ref name="NotFound"/>
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
<action name="NotFound">
<result type="redirect">/error.jsp</result>
</action>
</package>
<package name="root" extends="struts-default" namespace="/">
<!-- Sidebar menu item and static link actions -->
<action name="Home" class="com.opensymphony.xwork2.ActionSupport">
<result>/WEB-INF/jsp/index.jsp</result>
</action>
<action name="Alpha" class="com.opensymphony.xwork2.ActionSupport">
<result>/WEB-INF/jsp/alpha.jsp</result>
</action>
<action name="Beta" class="com.opensymphony.xwork2.ActionSupport">
<result>/WEB-INF/jsp/beta.jsp</result>
</action>
<!-- Actions -->
<action name="AnAction" class="action.AnAction">
<result name="success">/WEB-INF/jsp/index.jsp</result>
<result name="input">/WEB-INF/jsp/beta.jsp</result>
</action>
</package>
</struts>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org