0
我通過將字符串格式編碼爲UTF-8來保存列表。但是我看到{
,}
,:
...以及更多符號都在Cookie值中。如何解碼來自Cookie的Unicode字符
%7B%22evt%22%3A%5B%5D%2C%22exc%22%3A%5B%5D%2C%22tourQuantity%22%3A%221%22%2C%22tourId%22%3A%22067e61623b6f4ae2a1712470b63dff00%22%2C%22room%22%3A%7B%22accId%22%3A%226%22%2C%22roomTypeId%22%3A%225%22%7D%7D
上面一個是存儲在cookie中的值。
public ResponseEntity <ModelAndView> saveReservation(@RequestBody String reservation, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Cookie cookie = new Cookie("tourReservation", URLEncoder.encode(reservation, "UTF-8"));
cookie.setMaxAge(24 * 60 * 60);
cookie.setPath("/tour/reservation");
response.addCookie(cookie);
List <?> list = service.saveRes(reservation);
if (list.size() > 0) {
.........
return new ResponseEntity <ModelAndView> (model, HttpStatus.OK);
}
return new ResponseEntity <ModelAndView> (new ModelAndView("tour"), HttpStatus.BAD_REQUEST);
}
如何獲得我的列表字符串格式良好?我也用StringEscapeUtils
,我得到了一個錯誤java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value
。
org.apache.commons.lang.StringEscapeUtils.unescapeJava(reservation)