JAVAEE开发之POST/GET提交乱码解决总结
2011-11-13 23:07
656 查看
1,jsp表单提交到servlet默认为get提交;
2,get表单提交乱码处理最常见的是在tomcat服务器下把server.xml里面的8080端口后面加上URIEncoding="UTF-8",第二种方法是在后台得到get提交的参数后使用
String param=new String(request.getParameter("参数名").getBytes("iso-8859-1"),"UTF-8");
3,post表单提交乱码处理则为在后台使用方法request.setCharacterEncoding("UTF-8");即可。
4。超链接为GET提交,超链接提交出现乱码没有表单提交处理乱码哪么简单,要处理超链接提交,首先在server.xml里面增加UTIEnding="UTF-8"是必须的,然后若超链接中传递的参数为偶数个中文汉字,刚不须再处理乱码,若为奇数则用方法encodeURI('site.action?name=中文乱码');但是这样处理乱码有点麻烦为了解决不管参数的奇偶性也能处理乱码个 可以采用C标签:
<c:url value="login/login!login.action" var="url">
<c:param name="name" value="中文乱码s"></c:param>
</c:url>
<a href="${url}">提交</a>
5,jsp表单提交到action默认为post提交;POST提交不须再处理乱码因为struts已经在过滤器里面帮你把乱码处理了
6,ajax POST和GET提交乱码处理
在AJAX提交中要把参数和URL分离开来处理
var xmlHttp;
//自动加载国家
function country() {
var text = "sql=SELECT co_name FROM COUNTRY order by nvl(length(trim(co_name)),0) asc,co_name";
var url = "ajax/ajax!selectName.action";
createXmlhttp();
if (xmlHttp) {
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Cache-Control", "no-cache");
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
parseMessage('country');
}
}
xmlHttp.send(text);
}
}
其中 xmlHttp.setRequestHeader("Cache-Control", "no-cache");
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");这个要加上
action中:HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("html/xml;charset=gb2312");
response.setCharacterEncoding("UTF-8");
2,get表单提交乱码处理最常见的是在tomcat服务器下把server.xml里面的8080端口后面加上URIEncoding="UTF-8",第二种方法是在后台得到get提交的参数后使用
String param=new String(request.getParameter("参数名").getBytes("iso-8859-1"),"UTF-8");
3,post表单提交乱码处理则为在后台使用方法request.setCharacterEncoding("UTF-8");即可。
4。超链接为GET提交,超链接提交出现乱码没有表单提交处理乱码哪么简单,要处理超链接提交,首先在server.xml里面增加UTIEnding="UTF-8"是必须的,然后若超链接中传递的参数为偶数个中文汉字,刚不须再处理乱码,若为奇数则用方法encodeURI('site.action?name=中文乱码');但是这样处理乱码有点麻烦为了解决不管参数的奇偶性也能处理乱码个 可以采用C标签:
<c:url value="login/login!login.action" var="url">
<c:param name="name" value="中文乱码s"></c:param>
</c:url>
<a href="${url}">提交</a>
5,jsp表单提交到action默认为post提交;POST提交不须再处理乱码因为struts已经在过滤器里面帮你把乱码处理了
6,ajax POST和GET提交乱码处理
在AJAX提交中要把参数和URL分离开来处理
var xmlHttp;
//自动加载国家
function country() {
var text = "sql=SELECT co_name FROM COUNTRY order by nvl(length(trim(co_name)),0) asc,co_name";
var url = "ajax/ajax!selectName.action";
createXmlhttp();
if (xmlHttp) {
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Cache-Control", "no-cache");
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
parseMessage('country');
}
}
xmlHttp.send(text);
}
}
其中 xmlHttp.setRequestHeader("Cache-Control", "no-cache");
xmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");这个要加上
action中:HttpServletResponse response= ServletActionContext.getResponse();
response.setContentType("html/xml;charset=gb2312");
response.setCharacterEncoding("UTF-8");
相关文章推荐
- java中form以post、get方式提交数据中文乱码问题总结
- get/post 提交乱码问题解决(未使用过滤器)——Servlet解决
- tomcat post提交和get提交产生乱码的解决办法
- java中form以post、get方式提交数据中文乱码问题总结
- javaweb之request乱码解决(数据提交以post方式和get方式)
- get、post方法提交时的乱码问题解决
- 解决Get和Post请求中中文乱码问题 (2013-01-26 23:59:39)转载▼ 标签: javaee it 分类: JavaEE 对于Post请求,只需在Servlet或者jsp中写入如下
- Post与Get提交使用过滤器解决中文乱码问题
- struts2默认能解决get和post提交方式的乱码问题吗?
- SpringMVC第六篇——解决中文乱码(POST/GET提交)
- 找到一篇关于form以post、get方式提交数据中文乱码问题总结
- 用Filter解决GET和POST提交的中文乱码方法
- 解决post、get提交中文乱码问题
- 解决中文乱码的filter(包括get和post提交两种方式)
- Spring MVC 3 表单中文提交post请求和get请求乱码问题的解决方法
- 过滤器解决get和post方式提交的中文乱码
- 解决springmvc的get提交和post提交的中文乱码问题
- 用Filter解决GET和POST提交的中文乱码方法
- servlet的生命周期、解决乱码的方式和get方式提交与post方式提交的区别 学习笔记
- java中form以post、get方式提交数据中文乱码问题总结