ajax get 到servlet 解决utf-8中文乱码

前端之家收集整理的这篇文章主要介绍了ajax get 到servlet 解决utf-8中文乱码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<script type="text/javascript">

 function  save(){
  var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+,Firefox,Chrome,Opera,Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6,IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  
  	alert("ppp");
  	
  var deviceImgDate = document.getElementById("deviceImgDate").value;
  var deviceCheck1 = document.getElementById("deviceCheck1").value;
  var deviceCheck2 = document.getElementById("deviceCheck2").value;
  var deviceCheck3 = document.getElementById("deviceCheck3").value;
  var deviceCheck4 = document.getElementById("deviceCheck4").value;
  var deviceCheck5 = document.getElementById("deviceCheck5").value;
  var deviceCheck6 = document.getElementById("deviceCheck6").value;
  var deviceCheck7 = document.getElementById("deviceCheck7").value;
  var deviceCheck8 = document.getElementById("deviceCheck8").value;
  var deviceCheck9 = document.getElementById("deviceCheck9").value;
  var deviceCheck10 = document.getElementById("deviceCheck10").value;
  var deviceCheck11 = document.getElementById("deviceCheck11").value;
  var deviceCheck12 = document.getElementById("deviceCheck12").value;
  var deviceCheck13 = document.getElementById("deviceCheck13").value;
  var deviceCheck14 = document.getElementById("deviceCheck14").value;
  var deviceCheck15 = document.getElementById("deviceCheck15").value;
  var deviceScope = document.getElementById("deviceScope").value;
  
	var url="deiviceImgCheckServlet?deviceImgDate="+encodeURI(deviceImgDate)+"&deviceCheck1="+encodeURI(deviceCheck1)
	+"&deviceCheck2="+encodeURI(deviceCheck2)+"&deviceCheck3="+encodeURI(deviceCheck3)+"&deviceCheck4="+encodeURI(deviceCheck4)
	+"&deviceCheck5="+encodeURI(deviceCheck5)+"&deviceCheck6="+encodeURI(deviceCheck6)+"&deviceCheck7="+encodeURI(deviceCheck7)
	+"&deviceCheck8="+encodeURI(deviceCheck8)+"&deviceCheck9="+encodeURI(deviceCheck9)+"&deviceCheck10="+encodeURI(deviceCheck10)
	+"&deviceCheck11="+encodeURI(deviceCheck11)+"&deviceCheck12="+encodeURI(deviceCheck12)+"&deviceCheck13="+encodeURI(deviceCheck13)
	+"&deviceCheck14="+encodeURI(deviceCheck14)+"&deviceCheck15="+encodeURI(deviceCheck15)+"&deviceScope="+encodeURI(deviceScope);
	alert(url);
	xmlhttp.open("post",url,true);
	xmlhttp.send(null);
	alert("aaa");
	window.location.reload();
   	
   }

</script>
jsp: servlet/MsgServlet?userName=encodeURI('张三'),用encodeURI方法处理的都是UTF-8的 servlet: URLDecoder.decode(request.getParameter("userName").getString(),"UTF-8"));

猜你在找的Ajax相关文章