Aja乱码解决方案.doc

上传人:rrsccc 文档编号:9705123 上传时间:2021-03-18 格式:DOC 页数:4 大小:14KB
返回 下载 相关 举报
Aja乱码解决方案.doc_第1页
第1页 / 共4页
Aja乱码解决方案.doc_第2页
第2页 / 共4页
Aja乱码解决方案.doc_第3页
第3页 / 共4页
Aja乱码解决方案.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《Aja乱码解决方案.doc》由会员分享,可在线阅读,更多相关《Aja乱码解决方案.doc(4页珍藏版)》请在三一文库上搜索。

1、Ajax乱码解决方案页面端: xxert title here Ajax:function veryfy() /乱码问题解决: /1.页面端发送的数据采用encodeURI,encodeURI($(“#username”).val(),服务器端采用new String(str.getBytes(“iso8859-1”,”utf-8”); /2.页面端发送的数据采用两次encodeURI,encodeURI(encodeURI($(“#username”).val(),服务器端URLDecoder.decode(str,”utf-8”); $.get(“AjaxSeverlet?name=“ +

2、 encodeURI($(“#username”).val(), null, function(data) $(“#msg”).(data); ); 服务器端:public void doPost(ServletRequest request, ServletResponse response) throws ServletException, IOException request.setCharacterEncoding(“gb2312”); response.setHeader(“charset”,”gb2312”); /设置返回页面的头 meta 信息 response.setCont

3、entType(“text/;charset=gb2312”); /设置输出的文档类型 / 以上内容在PrintWriter 声明前设置,杜绝乱码 PrintWriter out=response.getWriter(); /接收参数实例:(Ajax页面端到服务器端) String s = request.getParameter(“name”); s = new String(s.getBytes(“iso-8859-1”), “utf-8”); System.out.println(s); /服务器端到页面端: / out.print(“Ajax乱码解决”); /直接输出中文 /x x从数据库中取中文数据 x/ SqlTools st = new SqlTools(); ResultSet rs = st.getResultSet(“select seller from orders where orderid = 1”); String dbs = “; try if(rs.next() dbs = rs.getString(“seller”); catch (SQLException e) / TODO Auto-generated catch block e.printStackTrace(); out.print(dbs); 4 / 4

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1