假设URL地址为:http://192.168.1.4:8080/Hello/servlet/LinkClient?text1=打算的&text2=ljz
request.setCharacterEncoding("ISO-8859-1");
response.setContentType("text/xml;charset=gbk");
response.setCharacterEncoding("gbk");
PrintWriter out = response.getWriter();
//*************这个是重点****************************************
String title = new String(request.getParameter("text1").getBytes("ISO-8859-1"),"utf-8");
String timelength = new String(request.getParameter("text2").getBytes("ISO-8859-1"),"utf-8");
timelength = URLDecoder.decode(timelength, "gbk");
title = URLDecoder.decode(title, "gbk");
out.println("<?xml version=\"1.0\" encoding=\"gbk\" ?>");
out.println("<book>");
out.println("<name>java高级编程</name>");
out.println(" <price>12</price>");
out.println(" <id>111111</id>");
out.println(" <text1>"+title+"</text1>");
out.println(" <text2>"+timelength+"</text2>");
out.println("</book>");
out.flush();
out.close();
进行传递,接收后在后台用
进行解码即可。
也可以用javascript的方法如
服务器端接收后也需要转一下码
即可.
或者使用
进行转码.