编写拦截器的两种方法:
1、继承AbstractInterceptor类,重写intercept方法()这里对拦截到的内容进行处理
/**
* 登录拦截器
*/
package com.abc.hotel.interceptor;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.abc.hotelsys.domain.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* @author 别说难忘记
*
*/
public class LoginInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
String path = ServletActionContext.getRequest().getRequestURI();
if(path.contains("getImageCode")||path.contains("checkLogin")||path.contains("toLogin")) {
return invocation.invoke();
}
ActionContext actionContext = ActionContext.getContext();
Map<String, Object> session = action