0

In struts2 i have one default interceptor and lot of actions in the struts.xml page.

My struts.xml is like this

<struts>
   <package>
       <interceptors>
         <interceptor-ref name="" class="" >
           <interceptor-stack name=""  >
               <interceptor-ref name="" />
               <interceptor-ref name="" />
            </interceptor-stack>
         </interceptor-ref>
       </interceptors>



       <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

   </package>
</struts>

In the default interceptor i have check the session. But if session is not set i need to redirect the page to login page, hence it should be work in all actions?. How do i implement this. Do i need to call the interceptor in all action or if i use default interceptor how can i set the redirect page in all actions?.

Cœur
  • 37,241
  • 25
  • 195
  • 267
anoop
  • 1,604
  • 6
  • 24
  • 50

1 Answers1

0

For this purpose you can make your own interceptor that will check if session is set or not. If it is not set it will redirect your request to login page. And then you can add this interceptor to the default interceptor stack where ever you want. And you don't need to call the interceptor each time, the struts2 framework will automatically call the interceptor before and after every action.

You can check from here how to make your own interceptor.

gprathour
  • 14,813
  • 5
  • 66
  • 90