過濾器 防止直接在瀏覽器輸入url進入頁面

過濾器 防止直接在瀏覽器輸入url進入頁面html

Jfinal框架 java

public class UrlHandler extends Handler{

@Override

public void handle(String target, HttpServletRequest request,

HttpServletResponse response, boolean[] isHandled){

    

HttpSession session=request.getSession();

String url=request.getRequestURI();

if(url.indexOf("Mngr")>0){

String usertype=(String) session.getAttribute("userType");

if(usertype==null||

(usertype!=null&&!usertype.equals(Constant.ADMIN))){

try {

response.sendRedirect(request.getContextPath()+File.separator+"pages"+File.separator+"login.html");

} catch (IOException e) {

e.printStackTrace();

}

}

}

nextHandler.handle(target, request, response, isHandled);

}

}
相關文章
相關標籤/搜索