- <%
- //一个有中文内容的Cookie
- String str = "我们都有一个家,名字叫中国!";
- Cookie cookie = new Cookie("name", URLEncoder.encode(str, "UTF-8"));
- response.addCookie(cookie);
- //取出Cookie中的中文内容
- Cookie [] cookies = request.getCookies();
- String str = "";
- for(int i=0;i<cookies.length;i++){
- if(cookies[i].getName().equals("name")) {
- str = cookies[i].getValue();
- }
- }
- out.println(URLDecoder.decode(str, "UTF-8"));
- %>
- //该片段来自于http://www.codesnippet.cn/detail/240420132985.html
来源: http://www.codesnippet.cn/detail/240420132985.html