日期:2014-05-19 浏览次数:20650 次
<?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>
<package name="bqyf" extends="struts-default">
<interceptors>
<!-- 定义权限拦截器 -->
<interceptor name="sessionInUser" class="com.pb.bqyf.command.SessionInUserInterceptor"></interceptor>
<!-- 定义拦截器栈 -->
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack"></interceptor-ref>//默认的拦截器引用
<interceptor-ref name="sessionInUser"></interceptor-ref>自己定义的拦截器引用
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"></default-interceptor-ref>
<global-results>//定义的全局拦截器
<result name="againIndex">index.jsp</result>
</global-results>
//登陆验证
<action name="loginAction" class="com.pb.bqyf.user.web.LoginAction">
<result name="main">/WEB-INF/jsp/main/LoginInfo.jsp</result>
<result name="index">index.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
//跳转到main页面 里面将各个页面分别通过<frameset></frameset>分页显示
<action name="mainAction" class="com.pb.bqyf.user.web.MainAction">
<result name="top">/WEB-INF/jsp/main/top.jsp</result>
<result name="left">/WEB-INF/jsp/main/left.jsp</result>
<result name="right">/WEB-INF/jsp/main/right.jsp</result>
</action>
</package>
</struts>
public class SessionInUserInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation arg0) throws Exception {
Map<String, Object> session = arg0.getInvocationContext().getSession();
User u = (User) session.get("user");
System.out.println(u.getUsername()+" "+u.getPassword());
String forword = "";
if(u!=null){
arg0.invoke();
}else{
forword = "againIndex";
}
return forword;
}
}