xml version="1.0" encoding= "UTF-8" ?>

DOCTYPE struts PUBLIC

     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

     "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name ="struts.devMode" value= "true">constant >

    <constant name= "struts.enable.DynamicMethodInvocation" value= "true">constant >

     <package name ="test" namespace="/" extends= "struts-default">

     

     <interceptors >

           <interceptor name ="authority" class= "com.cola.interceptor.AuthorizationInterceptor" >interceptor >

     interceptors >    

       

     <global-results >

           <result name ="login">/login.jsp result>

     global-results >

           <action name ="test" class= "com.cola.action.TestAction" method ="execute">

               <result name ="success" type= "dispatcher">/test.jspresult >

              

               <interceptor-ref name= "defaultStack">interceptor-ref >

               <interceptor-ref name= "authority">interceptor-ref >

           action >

     package >

     <include file ="struts2.xml"> include>

struts>

--------------------------------------------------

package com.cola.interceptor;


import java.util.Map;


import com.cola.bean.User;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.interceptor.Interceptor;


@SuppressWarnings("all" )

public class AuthorizationInterceptor implements Interceptor{


     @Override

     public void destroy() {

           // TODO Auto-generated method stub

          

     }


     @Override

     public void init() {

           // TODO Auto-generated method stub

          

     }


     @Override

     public String intercept(ActionInvocation ai) throws Exception {

          Map session = ai.getInvocationContext().getSession();

          User user = (User) session.get( "user");

           if( user!= null){

               return ai.invoke();

          }

           return Action. LOGIN;

     }



}