拦截器类:
package com.eduAskFoLeaveSystem.business.util;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class studentLoginInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// 取得请求相关的ActionContext实例
ActionContext ctx = invocation.getInvocationContext();
Map session = ctx.getSession();
// String user = (String) session.get(Constants.USER_SESSION);
String logintype = (String)session.get("logintype");
if ( session.get("login")!= null && logintype.equals("学生")) {
System.out.println("学生您已经登录");
return invocation.invoke();
}
ctx.put("tip", "你还没有登录");
return "login";
}
}
structs.xml配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<!-- struts的URL扩展名 -->
<constant name="struts.action.extension" value="do" />
<!-- 允许访问静态成员变量 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<constant name="struts.custom.i18n.resources" value="i18n/messages"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<!--
访问路径为http://localhost:8080/eduAskFoLleaveSystem/pages/ascForLeavecoreBusinessAction!test2.do
-->
<package name="eduAskFoLeaveSystem" namespace="/pages" extends="struts-default">
<!-- 定义一个拦截器 -->
<interceptors>
<interceptor name="studentLoginInterceptor"
class="com.eduAskFoLeaveSystem.business.util.studentLoginInterceptor">
</interceptor>
<interceptor name="managerLoginInterceptor"
class="com.eduAskFoLeaveSystem.business.util.managerLoginInterceptor">
</interceptor>
<interceptor name="teacherLoginInterceptor"
class="com.eduAskFoLeaveSystem.business.util.teacherLoginInterceptor">
</interceptor>
<interceptor name="sysuserLoginInterceptor"
class="com.eduAskFoLeaveSystem.business.util.sysUerLoginInterceptor">
</interceptor>
<!-- 拦截器栈 -->
<interceptor-stack name="student">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="studentLoginInterceptor" />
</interceptor-stack>
<interceptor-stack name="manager">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="managerLoginInterceptor" />
</interceptor-stack>
<interceptor-stack name="teacher">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="teacherLoginInterceptor" />
</interceptor-stack>
<interceptor-stack name="sysuser">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="sysuserLoginInterceptor" />
</interceptor-stack>
</interceptors>
<!-- 全局返回结果,用来判断错误以及跳转到登录 -->
<global-results>
<result name="error">/error.jsp</result>
<result name="login">/login.jsp</result>
</global-results>
<!-- 管理员模块 -->
<action name="SysUserAction" class="com.eduAskFoLeaveSystem.business.action.SysUserAction">
<interceptor-ref name="sysuser" />
<result name="Allteacher">/sysuser/showteacher.jsp</result>
<result name = "Allstudent">/sysuser/showstudent.jsp</result>
<result name = "Allmanager">/sysuser/showmanager.jsp</result>
<result name = "Allsysuser">/sysuser/showsysuser.jsp</result>
<result name = "addstudent">/sysuser/addstudent.jsp</result>
<result name = "addteacher">/sysuser/addteacher.jsp</result>
<result name = "addmanager">/sysuser/addmanager.jsp</result>
<result name ="addsysUser">/sysuser/addsysUser.jsp</result>
<result name="handleSuccess">/sysuser/handleSuccess.jsp</result>
<result name="handleFail">/sysuser/handleFail.jsp</result>
<result name="updateStudent">/sysuser/updateStudent.jsp</result>
<result name="updateTeacher">/sysuser/updateteacher.jsp</result>
<result name="updateManager">/sysuser/updatemanager.jsp</result>
<result name="updatesysUser">/sysuser/updatesysUser.jsp</result>
</action>
<!-- 学生信息管理模块 -->
<action name="StudentAction" class="com.eduAskFoLeaveSystem.business.action.StudentAction">
<interceptor-ref name="student" />
<result name = "AllAgreeLeave">/student/AllAgreeLeave.jsp</result>
<result name = "AllDisagreeLeave">/student/AllDisagreeLeave.jsp</result>
<result name = "AllnotagreeLeave">/student/AllnotagreeLeave.jsp</result>
<result name="addleave">/student/addLeave.jsp</result>
<result name="handleSucess">/student/handleSuccess.jsp</result>
<result name="handleFail">/student/handleFail.jsp</result>
<result name="showdetail">/student/showDetail.jsp</result>
<result name = "AllLeave">/student/AllLeave.jsp</result>
</action>
<!-- 登录管理模块 -->
<action name="LoginAction" class="com.eduAskFoLeaveSystem.business.action.LoginAction">
<result name="studentindex" >/student/AllLeave.jsp</result>
<result name = "teacherindex" >/teacher/AllnotagreeLeave.jsp</result>
<result name = "managerindex" >/manager/AllnotagreeLeave.jsp</result>
<result name = "SysUserindex" >/sysuser/sysuserindex.jsp</result>
</action>
<!-- 教师管理模块 -->
<action name="TeacherAction" class="com.eduAskFoLeaveSystem.business.action.TeacherAction">
<interceptor-ref name="teacher" />
<result name="agreesuccess">/teacher/agreesuccess.jsp</result>
<result name = "agreefail">/teacher/fail.jsp</result>
<result name = "disagreesucess">/teacher/agreesucess.jsp</result>
<result name = "disagreefail">/teacher/fail.jsp</result>
<result name = "AllAgreeLeave">/teacher/AllAgreeLeave.jsp</result>
<result name = "AllDisagreeLeave">/teacher/AllDisagreeLeave.jsp</result>
<result name = "AllnotagreeLeave">/teacher/AllnotagreeLeave.jsp</result>
<result name = "AllLeave">/teacher/AllLeave.jsp</result>
</action>
<!-- 系领导管理 -->
<action name="ManagerAction" class="com.eduAskFoLeaveSystem.business.action.ManagerAction">
<interceptor-ref name="manager" />
<result name="agreesuccess">/manager/agreesuccess.jsp</result>
<result name = "agreefail">/manager/fail.jsp</result>
<result name = "disagreesucess">/manager/agreesucess.jsp</result>
<result name = "disagreefail">/manager/fail.jsp</result>
<result name = "AllAgreeLeave">/manager/AllAgreeLeave.jsp</result>
<result name = "AllDisagreeLeave">/manager/AllDisagreeLeave.jsp</result>
<result name = "AllnotagreeLeave">/manager/AllnotagreeLeave.jsp</result>
<result name = "AllLeave">/manager/AllLeave.jsp</result>
</action>
</package>
</struts>