Struts2拦截器权限验证(源码)

http://www.cnblogs.com/shiyangxt/archive/2008/10/24/1318673.html
长话短说,抛砖引玉,举个很简单的例子,通过Session,验证用户是否已登陆。

环境:MyEclipse6.5+Mysql5+struts2.0.11.2

源码:拦截器类:

AuthInterceptor.java

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

<!DOCTYPE struts PUBLIC

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

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

<struts>

    <package name="News" extends="struts-default">



    <interceptors>



    <interceptor-stack name="myStack">

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

                <interceptor-ref name="auth"></interceptor-ref>

    </interceptor-stack>

   

    <interceptor name="auth" class="com.sy.interceptor.AuthInterceptor"/>

    </interceptors>



    <global-results>

        <result name="login" type="redirect">/admin/login.jsp</result>

    </global-results>

<!-- 验证管理员登陆 -->

        <action name="login" class="com.sy.action.AdminAction">

            <result name="failure">/admin/failure.jsp</result>

            <result>/admin/ManageNews.jsp</result>

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

        </action>

<!-- 管理员列表 -->       

        <action name="alist" class="com.sy.action.ListAction" method="adminList">

            <result>/admin/deleteManager.jsp</result>

            <result name="failure">/admin/Showfailure.jsp</result>

            <interceptor-ref name="myStack"></interceptor-ref>

        </action>

    </package>

</struts>

你可能感兴趣的:(struts)