日期:2014-05-17  浏览次数:20632 次

简单的拦截器问题
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<filter>
<filter-name>loginfilter</filter-name>
<filter-class>ora.rjxy.filter.Myfilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>




public class Myfilter implements Filter {
String encoding = "UTF-8";

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterchain) throws IOExceptionServletException {
HttpServletRequest request1 = (HttpServletRequest) request;
HttpServletResponse response1 = (HttpServletResponse) response;
request1.setCharacterEncoding(encoding);
response1.setCharacterEncoding(encoding);
HttpSession session = request1.getSession();
String name = (String) request.getAttribute("name");
if (name != null && !name.equals("")) {
filterchain.doFilter(request1, response1);
} else {
response1.sendRedirect("Login.jsp");
}

}

public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

提示:此网页包含重定向循环
http://localhost:8080/NewsStore/Login.jsp 的网页生成了 过多的重定向。清除此网站的 Cookie 或允许第三方 Cookie 可能会解决该问题。如果 不能解决,则可能是服务器配置的问题,而不是您的 计算机有问题。
错误 怎么解决?望高手腾出时间帮我解决一下?
------解决方案--------------------
你重定向到Login.jsp的时候他也过滤掉了,不要过滤login.jsp页面,你用request得到访问的URI,在后面再加一个判断,判断URI结尾是不是有Login.jsp