1,jsp表单提交到servlet默认为get提交; html
2,get表单提交乱码处理最多见的是在tomcat服务器下把server.xml里面的8080端口后面加上URIEncoding="UTF-8",第二种方法是在后台获得get提交的参数后使用ajax
String param=new String(request.getParameter("参数名").getBytes("iso-8859-1"),"UTF-8");sql
3,post表单提交乱码处理则为在后台使用方法request.setCharacterEncoding("UTF-8");便可。tomcat
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>app
5,jsp表单提交到action默认为post提交;POST提交不须再处理乱码由于struts已经在过滤器里面帮你把乱码处理了 jsp
6,ajax POST和GET提交乱码处理ide
在AJAX提交中要把参数和URL分离开来处理post
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);
}
}url
其中 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");