我想实现一个过滤器来执行身份验证,但不知何故它被卡住在无限循环中......任何想法都会被赞赏。Java Filter无限循环
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
doBeforeProcessing(request, response);
Throwable problem = null;
HttpSession session = httpRequest.getSession(true);
if(session.getAttribute("userName")!=null&&session.getAttribute("userName")!=(""))
{
try {
chain.doFilter(request, response);
} catch (Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that.
problem = t;
t.printStackTrace();
}
}else{
httpResponse.sendRedirect("login.jsp");
return;
}
这段代码在调试模式只是在无限的时间运行,basicly我希望将用户重定向到的login.jsp时未登录他。 任何答复赞赏。
这是过滤器也对'login.jsp'运行页? – doublesharp
是的,不幸的。无论如何,我提出了一个解决方案: “如果(uri.indexOf(” login.jsp的“)> - 1){ \t \t \t chain.doFilter(请求,响应); //只要继续链 \t \t \t返回; \t \t}“ – czupe
或者是否有更优雅的方式从过滤中排除login.jsp?我想在web.xml中的一些行,但据我所知它不支持这标记或类似此功能:( –
czupe