我的过滤器哪里写错了?

kien5 kien5 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>
tools.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>




public class SetCharacterEncodingFilter implements Filter {

protected FilterConfig filterConfig;
protected String encodingName;
protected boolean enable;

public SetCharacterEncodingFilter() {
encodingName = "UTF-8";
enable = false;
}

// 初始化
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

// 每个请求设置UTF-8
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");

HttpServletRequest httprequest = (HttpServletRequest) request;
HttpServletResponse httpresponse = (HttpServletResponse) response;
HttpSession session = httprequest.getSession();
AdminUser user=new AdminUser();
try { //获得在session中所记录的isLogin属性,该属性由登录部分的代码写入
user = (ActingAdminUser) session.getAttribute("user");
if (user!=null) //验证成功,继续处理
{
chain.doFilter(request, response);
} else //验证不成功,让用户登录。
{
String targetURL = httprequest.getContextPath()+"/login.jsp";
httpresponse.sendRedirect(targetURL);
}
} catch (Exception e) {
e.printStackTrace();
}

}
public void destroy() {
}
}



我想实现判断session用户是否登录了
我配了这个,是在编码过滤器那里顺便加点session判断,但是我开个网页都卡在那里,好像在反复重定向,左下角闪烁正在打开"http://localhost:8080/test/login.jsp" 和 "正在重新定向到http://localhost:8080/test/login.jsp" 我写错哪里了?
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
kien5
Web 开发 81,108 成员 341,721 内容