java web 项目 添加登陆过滤器后,出现“此网页包含重定向循环”问题 5
代码:publicclassLoginFilterimplementsFilter{privateFilterConfigfc;//无须过滤的页面publicstatic...
代码:public class LoginFilter implements Filter{ private FilterConfig fc; //无须过滤的页面 public static String[] Nofilter_Pages={ "/index.jsp", "/login.jsp", "/loginServlet", }; @Override public void init(FilterConfig fc) throws ServletException { this.fc=fc; } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterchain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String path=req.getRequestURL().toString(); HttpSession session=req.getSession(true); //从session里取得用户名信息 String user=(String) session.getAttribute("user"); for(int i=0; i-1) { filterchain.doFilter(req, res); } } //如果没有读取到登陆用户,就跳转到登陆界面 if (user==null || "".equals(user)) { //跳转登陆界面 res.sendRedirect(req.getContextPath()+"/login.jsp"); } else{ //已经登录,继续此次请求 filterchain.doFilter(request, response); } }
展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏5(财富值+成长值)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询