日期:2014-05-18 浏览次数:20708 次
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* 拦截学生未登录就去访问一些action
* @author Administrator
*
*/
public class StudentLoginInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
Map<String, Object> session = ctx.getSession();
Student student = (Student) (session.get("STUDENT_LOGIN"));
if (student != null)
return invocation.invoke();
return Action.LOGIN;
}
}
<result name="LOGIN" type="redirect">/page/index/index.jsp</result>
</global-results>
<interceptors>
<interceptor name="studentLoginInterceptor"
class="beyond.library.interceptor.StudentLoginInterceptor">
</interceptor>
</interceptors>
<interceptor-ref name="studentLoginInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>