tomcat Cookie解码失败

在JavaWeb项目中用URL编码解码方法传递中文到jsp文件中,解码遭遇失败
LoginServlet的核心代码

if (user != null && password.equals(user.getPassword())) {
            resp.sendRedirect("/BrandProject/index.html");
        } else {
            String s = "密码或账号错误,请重新输入";
            s = URLEncoder.encode(s, "UTF-8");
            System.out.println("servlet:  "+s);
            Cookie cookie = new Cookie("err_info", s);
            cookie.setMaxAge(60*60);
            resp.addCookie(cookie);
            resp.sendRedirect(("/BrandProject/againLogin.jsp"));
        }

jsp解码部分代码:

Cookie[] cookies=request.getCookies();
    String err_info=null;
    for(Cookie c:cookies){
        String name=c.getName();
        if("err_info".equals(name)){
            err_info=c.getValue();
            System.out.println("jsp:  "+err_info);
            err_info= URLDecoder.decode(err_info,"UTF-8");
            System.out.println("value:  "+err_info);
            break;
        }
    }

控制台截图:

img

这说明传递参数过程中没出现问题,但是为什么会发生解码失败呢?

很明显编码格式没对上呀,你tomcat里不是utf8,你按utf8解码了。可以去设置tomcat的编码,或者试试用iso-8859-1或gbk解码