Because the value of the cookie is ASCII, it is not possible to directly assign the value of the custom cookie to Chinese, but there are methods to implement this function.
1.java has provided us with a method that only needs to be imported into the package.
<%@ page language="java" import="java.util.*,java.net.* " contenttype="text/html; Charset=utf-8"%>
2. Solve the problem of garbled characters in the page
<body> <%request.setcharacterencoding ("utf-8"); %></baby>
3. Use the Urlencoder.encode () method and the Urldecode.decode () method to perform this operation;
//Save user name and password in cookie objectString name =urlencoder.encode (Request.getparameter ("name"),"Utf-8") ;//use Urlencoder to resolve issues where you cannot save Chinese characters in cookiesString pwd = Urlencoder.encode (Request.getparameter ("pwd"),"Utf-8"); String type=urlencoder.encode (Request.getparameter ("type"),"Utf-8");
// when it is removed from the cookie to print String "utf-8");
java-jsp resolves an issue in which you cannot save Chinese characters in cookies