jfinal handler 实现登入验证
程序员文章站
2022-03-08 10:29:15
...
/**
* 实现登入拦截验证,未登入的.html请求会跳转到登入的页面,登入了则不会
*/
@Override
public void handle(String target, HttpServletRequest request,
HttpServletResponse response, boolean[] isHandled) {
// TODO Auto-generated method stub
if (target.lastIndexOf(".html") != -1
&& target.lastIndexOf("login.html") == -1) {
Object object = request.getSession().getAttribute("objectid");
if (object == null || object.toString().equals("")) {
isHandled[0] = false;
try {
request.getRequestDispatcher("/unifyLogin/login.html")
.forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
next.handle(target, request, response, isHandled);
}