Error with cookie-value when adding a new Spring Session

前端 未结 5 1435
刺人心
刺人心 2020-12-14 20:22

In my Spring Boot 1.4 based application I use Spring Session to store session data in the database with JDBC.

This works fine

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 20:58

    Function cookie cannot encode properly the value with space also french signs and so on. I solve this problem with URLEncoder.encode(String arg0, Encoding version) here I used UTF-8. Here the method I created!

    private static void setCookie( HttpServletResponse response, String nom, String valeur, int maxAge )throws IOException { 
        Cookie cookie = new Cookie( nom, URLEncoder.encode( valeur, "UTF-8" ) );
        cookie.setMaxAge( maxAge );
        response.addCookie( cookie );
    }
    

提交回复
热议问题