欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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);
}
相关标签: handler