传500个中文到服务器端乱码问题解决
?? 传500个中文到服务器端乱码问题解决,挺有意思的东西,ajax传送默认是utf-8所以js就不设置编码了,注意点需要对&,+等一些特殊符号进行转码,可以用类似replace的方法进行转换。不过写replace进行转换可能有一点点疑惑,具体可以参考java的replace方法,呵呵。
public class AjaxService extends BaseService{ private static final long serialVersionUID = 1L; public String test() throws Exception { String type = request.getParameter("type"); response.setContentType("text/html charset=UTF-8"); response.setCharacterEncoding("UTF-8"); if (type == null) { response.getWriter().println("添加失败"); } else { System.out.println(type); response.getWriter().println("添加成功"); } return null; }}??