ext ajax 提交json对象给struts2,struts2无法解析对象
时间:2010-11-08
来源:互联网
前台:var obj ={"newid":"5"};
obj["hero.heroName"]="grg";
obj["hero.hid"]=6;
Ext.Ajax.request({
url: 'je/heroTest_giveHeroInfo',
method:"POST",
success: function(data){
Ext.Msg.show(data.responseText);
},
failure: function(){alert("failure");},
//这种方式,struts2只能接受到hero.hid,hero.heroName会为空
params:{'hero.heroName':'sdf','hero.hid':45}
//这种方式hero对象就为空了,什么都接受不到
//params: Ext.encode(obj)
});
je/heroTest_giveHeroInfo action:
public class HeroTestAction extends CommonAction {
private HeroTest hero;
public void setHero(HeroTest hero) {
this.hero = hero;
}
private int newid;
public void setNewid(int newid) {
this.newid = newid;
}
private String json;
public void setJson(String json) {
this.json = json;
}
public void giveHeroInfo() throws IOException{
System.out.println(json);
System.out.println("新ID:"+newid);
System.out.println("英雄的名字:"+hero.getHeroName());
System.out.println("英雄的id:"+hero.getHid());
sendMsg(hero.getHeroName());
//sendMsg(((Integer)newid).toString());
}
private void sendMsg(String content) throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.getWriter().write(content);
}
}
struts2.xml配置文件:
<package name="jsonExt" namespace="/je" extends="json-default">
<interceptors>
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myDefaultStack"/>
<action name="heroTest_*" class="com.foodchina.mbca.action.test.HeroTestAction" method="{1}">
<result type="json"/>
</action>
</package>
如红字所示,问题就是struts2无法接受ext ajax传过来的json对象。我使用jquery可以成功,但是ext我哪里做的不对?
obj["hero.heroName"]="grg";
obj["hero.hid"]=6;
Ext.Ajax.request({
url: 'je/heroTest_giveHeroInfo',
method:"POST",
success: function(data){
Ext.Msg.show(data.responseText);
},
failure: function(){alert("failure");},
//这种方式,struts2只能接受到hero.hid,hero.heroName会为空
params:{'hero.heroName':'sdf','hero.hid':45}
//这种方式hero对象就为空了,什么都接受不到
//params: Ext.encode(obj)
});
je/heroTest_giveHeroInfo action:
public class HeroTestAction extends CommonAction {
private HeroTest hero;
public void setHero(HeroTest hero) {
this.hero = hero;
}
private int newid;
public void setNewid(int newid) {
this.newid = newid;
}
private String json;
public void setJson(String json) {
this.json = json;
}
public void giveHeroInfo() throws IOException{
System.out.println(json);
System.out.println("新ID:"+newid);
System.out.println("英雄的名字:"+hero.getHeroName());
System.out.println("英雄的id:"+hero.getHid());
sendMsg(hero.getHeroName());
//sendMsg(((Integer)newid).toString());
}
private void sendMsg(String content) throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.getWriter().write(content);
}
}
struts2.xml配置文件:
<package name="jsonExt" namespace="/je" extends="json-default">
<interceptors>
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myDefaultStack"/>
<action name="heroTest_*" class="com.foodchina.mbca.action.test.HeroTestAction" method="{1}">
<result type="json"/>
</action>
</package>
如红字所示,问题就是struts2无法接受ext ajax传过来的json对象。我使用jquery可以成功,但是ext我哪里做的不对?
作者: elfenliedef 发布时间: 2010-11-08
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
我不敢肯定,但我觉得这个地方的配置应该是:
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="json"/>
</interceptor-stack>
</interceptors>
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
我不敢肯定,但我觉得这个地方的配置应该是:
<interceptor-stack name="myDefaultStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="json"/>
</interceptor-stack>
</interceptors>
作者: licip 发布时间: 2010-11-08
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28