1 / 11
文档名称:

09-解决ajax中文乱码及跨域访问.doc

格式:doc   大小:75KB   页数:11页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

09-解决ajax中文乱码及跨域访问.doc

上传人:jd234562 2016/8/13 文件大小:75 KB

下载得到文件列表

09-解决ajax中文乱码及跨域访问.doc

文档介绍

文档介绍:... ... : function verify() {//解决中文乱码问题的方法1,页面端发出的数据做一次encodeURI ,服务器端使用new String(("iso8859-1"), "UTF-8"); //解决中文乱码问题的方法 2,页面端发出的数据做两次 encodeURI ,服务器端使 (old, "UTF-8"); var userName =$("#userName").val(); $.get("AjaxServer?name="+encodeURI(encodeURI(userName)), null, function(data){ $("#result").html(data); }); }推荐使用方法 2,因为方法 1中使用硬编码“ISO-8859-1 ”了。 : import ; import ; import .URLDecoder; import ; import ; import ; import ; import ; import ; /** *Servlet implementation class AjaxServer */ ... ... ***@WebServlet(description ="wh description", urlPatterns ={"/AjaxServer" },initParams ={***@WebInitParam(name ="name", value ="", description ="wh name") }) public class AjaxServer extends HttpServlet { private static final long serialVersionUID =1L; /** ****@see HttpServlet#HttpServlet() */public AjaxServer() {super(); //TODO Auto-generated constructor stub }/** ****@see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse *response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {("text/html; charset=UTF-8"); //("UTF-8"); PrintWriter out =(); Integer inte =(Integer) ().getAttribute("total"); int temp =0; ... ... if(inte ==null) temp =1; else temp =() +1; ().setAttribute("total", temp); // String old =("name"); //String name =new String(("ISO-8859-1"), "UTF-8"); String name =(old, "UTF-8"); // if(old ==null ||() ==0){ (" 用户名不能为空"); }else {// if(("wangxingkui")) { //。这一步需要