Using struts.xml with a conditional plugin

It seems like it should be easy to do, but I just can get it to work. I am connected to the legend plugin in Struts 2.1. However, I need to define some configuration at the package level, such as a new interceptor stack and exception mapping. I would like to use the struts.xml file to do this, but I cannot get the convention-based packages corresponding to the struts.xml packages. My struts.xml looks like this:

<struts>
<constant name="struts.convention.default.parent.package" value="default"/>  
<package name="default" extends="struts-default">
</package>
<package name="root" namespace="/" extends="struts-default">
    <action name="index">
        <result>/index.jsp</result>
    </action>
</package>

<package name="my.package.actions.myaccount" namespace="/myaccount" extends="struts-default">
<interceptors>
    <interceptor name="authenticationInterceptor" class="my.package.interceptors.AuthenticationInterceptor"/>
    <interceptor-stack name="secureStack">
        <interceptor-ref name="authenticationInterceptor"/>
        <interceptor-ref name="defaultStack"/>
    </interceptor-stack>
</interceptors>

    <default-interceptor-ref name="secureStack"/>
</package>
</struts>

      

I have my interceptor in:
/ src / my / package / interceptors
and my actions in:
/ src / my / package / actions / myaccount

+1


source to share


1 answer


I understood that. I changed the package name above to just read "myaccount"

Then you can add this to a separate annotation action:

@ParentPackage(value = "myaccount")

      



Or to all activities in a package by adding the package-info.java file to the appropriate directory, which includes the following:

@org.apache.struts2.convention.annotation.ParentPackage(value = "myaccount") 

package com.mysite.actions.myaccount;

      

Hope this helps someone else for a while!

+6


source







All Articles