cookie中存中文

cookie中存中文

1:想要在cookie中存中文:需要用到URLEncoder(在jdkAPI中有介绍)

 

Cookie cookie = new Cookie("User",URLEncoder.encode(要编码的参数,"utf-8"));(编码后页面需要解码)

2:页面解码:

用js 解码。

w3c菜鸟教材中  EncoderURL可以完成解码操作:

事例代码:
<script type="text/javascript">
window.onload = function(){
var date = "${cookie.username.value}";
var username = decodeURI(date);
document.getElementById("_un").value = username;
}
</script>

原文地址:https://www.cnblogs.com/daishiwen/p/6551406.html