AJAX 解决传中文乱码问题
2013-06-12 12:17
369 查看
1.javascript代码
2.后台java代码
<script type="text/javascript"> //http://www.w3school.com.cn/ajax/index.asp var xmlHttp; function getCN(obj) { var author = document.forms[0].u367766562624002.value; //中文值 author=encodeURI(author); author=encodeURI(author); //传送的值,2次转码。 try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ //Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ // IE6, IE5 try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ alert("您的浏览器不支持AJAX!"); return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4 && xmlHttp.status==200){ var result=xmlHttp.responseText; document.forms[0].u367763762460602.value=result; } }; var url = "xzShow.do?show=getcn&uname="+author; xmlHttp.open("POST",url,true); xmlHttp.send(null); } </script>
2.后台java代码
public ActionForward execute(ActionMapping mapping, ActionForm actionform, HttpServletRequest request, HttpServletResponse response, SessionUser sessionuser) throws Exception { response.setContentType("text/html"); response.setCharacterEncoding("GBK"); PrintWriter out = response.getWriter(); String uname=StringUtils.trim(request.getParameter("uname")); uname=URLDecoder.decode(uname,"utf8"); //解码 System.out.println("-----"+uname); if(!uname.equals("")){ out.print("你好"); } out.close(); return null; }
相关文章推荐
- 解决ajax.net 1.0中文乱码问题!
- 解决ajax传递中文参数,出现乱码的问题
- jquery.ajax的url中传递中文乱码问题的解决方法
- 前台ajax传值到controller后,返回值中文乱码问题解决
- Ajax传输中文乱码问题的解决办法
- ajax解决中文数据乱码问题
- JAVA中应用AJAX的中文乱码问题的解决
- 解决ajax提交表单时中文乱码的问题
- Ajax技术之解决中文乱码问题
- ajax学习笔记---解决浏览器缓存和中文乱码问题
- 解决ajax请求中文参数乱码问题
- AJAX解决中文乱码问题
- ajax提交中文数据,乱码问题,困扰我整整两天。终于被我解决。。。
- 织梦gbk版本中ajax提交自定义表单中文乱码问题解决方法
- Minishowcase-AJAX/PHP开源相册解决中文翻译和中文乱码问题
- 一句话解决AJAX中文乱码问题
- asp+ajax解决中文乱码问题
- PHP中中Ajax中文乱码问题解决
- jsp中 ajax的get请求的中文乱码问题的解决方法