我使用jquery进行ajax验证,在action里面返回一个JSONObject对象。代码如下:List temp = packageService.queryCardBySeq(cardseq);
JSONObject jsonObj = new JSONObject();
if(temp!=null&&temp.size()>0){
Card card = (Card)temp.get(0);
jsonObj.accumulate("id", card.getId());
jsonObj.accumulate("card_code", card.getCard_code());
jsonObj.accumulate("card_name", card.getCard_name());
jsonObj.accumulate("card_seq", card.getCard_seq());
jsonObj.accumulate("card_value", card.getCard_value());
jsonObj.accumulate("tel_no", card.getTel_no());
out.print(jsonObj);
}页面上取msg.card_name时乱码,其他都正确(其他不含中文只有card_name含中文)。搞了一早上还是没能解决。该用的方法都用了。
response设置为utf-8,页面设置成utf-8,容器设成utf-8全都试过了还不行。有没有谁知道如何解决。尽量说点有实际作用的。对了下面是jsp请求 $.ajax({url: "${home}/sales/packagemg.do?cmd=checkCardIsAxist",
type:"post",
dataType:"json",
cache:false,
data:"cardseq="+obj.value,
success:function(msg){
if(msg==0){//返回的是0的话代表该串号不存在所以不能打包
alert("该卡不能打包!");
tempTd[0].children[0].value="";
tempTd[0].children[1].value="";
tempTd[2].children[0].value="";
tempTd[3].children[0].value="";
tempTd[4].children[0].value="";
obj.focus();
}else{//否则的话代表串号存在,则把返回的对象的各个属性加载到文本框中
tempTd[0].children[0].value=msg.card_code;
tempTd[0].children[1].value=msg.id;
tempTd[1].children[0].value=msg.card_seq;
tempTd[2].children[0].value=msg.tel_no;
tempTd[3].children[0].value=msg.card_name;
tempTd[4].children[0].value=msg.card_value;
}
}
});
JSONObject jsonObj = new JSONObject();
if(temp!=null&&temp.size()>0){
Card card = (Card)temp.get(0);
jsonObj.accumulate("id", card.getId());
jsonObj.accumulate("card_code", card.getCard_code());
jsonObj.accumulate("card_name", card.getCard_name());
jsonObj.accumulate("card_seq", card.getCard_seq());
jsonObj.accumulate("card_value", card.getCard_value());
jsonObj.accumulate("tel_no", card.getTel_no());
out.print(jsonObj);
}页面上取msg.card_name时乱码,其他都正确(其他不含中文只有card_name含中文)。搞了一早上还是没能解决。该用的方法都用了。
response设置为utf-8,页面设置成utf-8,容器设成utf-8全都试过了还不行。有没有谁知道如何解决。尽量说点有实际作用的。对了下面是jsp请求 $.ajax({url: "${home}/sales/packagemg.do?cmd=checkCardIsAxist",
type:"post",
dataType:"json",
cache:false,
data:"cardseq="+obj.value,
success:function(msg){
if(msg==0){//返回的是0的话代表该串号不存在所以不能打包
alert("该卡不能打包!");
tempTd[0].children[0].value="";
tempTd[0].children[1].value="";
tempTd[2].children[0].value="";
tempTd[3].children[0].value="";
tempTd[4].children[0].value="";
obj.focus();
}else{//否则的话代表串号存在,则把返回的对象的各个属性加载到文本框中
tempTd[0].children[0].value=msg.card_code;
tempTd[0].children[1].value=msg.id;
tempTd[1].children[0].value=msg.card_seq;
tempTd[2].children[0].value=msg.tel_no;
tempTd[3].children[0].value=msg.card_name;
tempTd[4].children[0].value=msg.card_value;
}
}
});
Servlet.service() for servlet default threw exception
java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/String;)Ljava/lang/Object;
at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:159)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept
在这段代码时card.getCard_name()是乱码吗?要是,有可能是数据库的问题,要不是就要转码
用UTF-8编码,用ISO-8859-1解码,然后再到前台看看是不是乱码,要是的话再处理下,没用过
JSON,不过原理应该一样
<%@ page language="java" contentType="text/html; charset=utf-8"%>原理不要讲了,我都懂。能否讲点能实际解决问题的办法
再次说明一下,数据从库里读出来没问题,仅仅是页面上取值时乱码了。页面编码格式,response返回的编码方式都改了。麻烦各位讲点实际能解决问题的方法。
你说的用fiddler分析能否讲明白点
用firefox的插件firebug也可以。
你既然不知道问题出在哪里,那就反证,确认每个细节都没问题。HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Vary: Accept-Encoding
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
Set-Cookie: AreYouHuman=7981; domain=.blogjava.net; path=/
X-Powered-By: ASP.NET
Date: Fri, 25 Dec 2009 05:05:26 GMT
Content-Length: 118608
connectionTimeout="20000"
redirectPort="8443" /> 里面加上URIEncoding="UTF-8"就行了
设置下,我这样设置解决了