0

我已经在我的应用程序中实现了 HandlerInterceptorAdapter,在 preHandle 方法中,我正在检查会话是否具有“用户”属性。如果为空,那么我将重定向发送到登录页面。

if ( request.getSession().getAttribute("user")==null) {  
            System.out.println("hello");
            response.sendRedirect("login.htm");
            return true;
            }

        return super.preHandle(request, response, handler);
    }

当我在浏览器中打开任何 url 时,我收到一条消息 Firefox 检测到服务器正在以永远不会完成的方式重定向对该地址的请求。

我该怎么办请建议我!!!!!!!!!!

4

1 回答 1

0
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public String indexView(HttpServletRequest request){

if ( request.getSession().getAttribute("user")==null) {  
    System.out.println("hello");
     return "redirect:/login.html"
    }
else 
   return "index";
}

坦率地说,我相信你应该使用 Spring Security。这是使用 Spring 实现 Web 容器安全性的更好、更少错误、更安全和快速的方法。

希望能帮助到你。

于 2012-04-27T12:05:41.040 回答