求助 strtus2的拦截器不执行intercept()这个方法、、、、、、、、
首先是 自定义拦截器.java代码
public class Filter extends AbstractInterceptor {
private List list = new ArrayList();
@Override
public String intercept(ActionInvocation actioninvocation) throws Exception {
// String servletPath = request.getServletPath();
// ActionContext context = actioninvocation.getInvocationContext();
// HttpServletRequest request =
// (HttpServletRequest)context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest");
System.out.println("进入过滤器");
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String servletPath = request.getServletPath();// 这里是得到你要访问的资源url
for (String url : list) {
if (servletPath.indexOf(url) > -1) {// 需要过滤
System.out.println("进入session过滤器->访问路径为[" + servletPath + "]");
if (request.getSession().getAttribute("user") == null) {// session不存在需要拦截
request.setAttribute("hint", "您还没有登录或登录已超时,请重新登录,然后再刷新本功能!");
request.getRequestDispatcher("/nosession.jsp")
.forward(request, response);
break;
}
break;
}
}
return actioninvocation.invoke();
}
@Override
public void init() {
System.out.println("初始化滤器");
list.clear();
list.add("/user/userAction_login.do");
}
然后是配置文件.xml
class="com.syyx.officemanage.common.utils.Filter" />
class="com.syyx.officemanage.user.action.UserAction">
/login.jsp
分享到:
更多
------解决方案--------------------
改成 o了