一、get请求中的中文乱码问题:
<form
>
<input
type="text" name
="username">
<input
type="submit" value
="提交">
</form
>
String username
= request
.getParameter(
"username");
String name
= URLEncoder
.encode(name,
"iso-8859-1");
username
= URLDecoder
.decode(name,
"utf-8");
String username
= request
.getParameter(
"username");
username
= new String(username
.getBytes(
"iso-8859-1"),
"utf-8");
二、 post请求 以上的方法,在post请求中一样可以用 在post请求中的另外的处理编码的方式 在接收参数前,设置下请求体的编码格式即可
request
.setCharacterEncoding(
"utf-8")
这句代码是转么针对请求体的数据进行编码处理,而在get请求中是不存在请求体的,post请求中,所有的请求参数都是封装在请求体中的,所以post中,可以通过这句代码,直接解决参数编码问题。
转载请注明原文地址: https://ju.6miu.com/read-38138.html