众所周知,前后台表单数据传送有两种方式——get和post
post方式
post方式比较简单,请求的数据是作为请求体的一部分传送给服务器,所以只要修改请求内的编码就行了。
页面上:
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
后台:
request.setCharacterEncoding("utf-8")
get方式
这里主要说下get方式,get方式请求时,其传送的数据是附到URL地址之后的,首先设置整个页面编码为utf-8
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
然后在页面上对传送的数据进行编码,再到后台进行解码
比如:
前台:
var name = decodeURIComponent(name,true);
window.open("system/down?name="+encodeURI((encodeURI(name))));
后台:
name = java.net.URLDecoder.decode(name,"utf-8");