我想實現一個過濾器來執行身份驗證,但不知何故它被卡住在無限循環中......任何想法都會被讚賞。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