当前位置:编程学习 > JAVA >>

Extjs4 访问struts2 的action方法不能完整执行

js文件:
function f1() {
Ext.QuickTips.init();
var simple = Ext.create('Ext.form.Panel',{
draggable: {
        insertProxy: false,//拖动时不虚线显示原始位置

        onDrag : function(e){
            var pel = this.proxy.getEl();
            this.x = pel.getLeft(true);
            this.y = pel.getTop(true);//获取拖动时panel的坐标
        },

        endDrag : function(e){
            this.panel.setPosition(this.x, this.y);//移动到最终位置
        }
    },
title : 'Demo',
bodyStyle : 'padding:5px 5px 0',
width : 350,
height:120,
fieldDefaults : {
    frame:true,
msgTarget : 'side',
labelWidth : 75
},
defaultType : 'textfield',
defaults : {
anchor : '100%'
},
items : [ {
fieldLabel : 'Text',
name : 'text',
allowBlank : false
} ],
buttons : [{
text : 'ajax',
listeners : {
click : function() {
var form=this.up('form').getForm();
form.submit({
url: '${pageContext.request.contextPath}/food/addFoodAjax.do',
waitMsg: 'loading...',
mthod:'post',
success: function(form, action){
                                alert(action.response.responseText);/* action.response.responseText */
                            },
                            failure: function(form, action){
                                alert(action.result.errormsg);
                            }
});
}
}
}, {
text : 'submit',
listeners:{
click:function(){
var form=this.up('form').getForm().dom;
form.action='${pageContext.request.contextPath}/food/addFood.do';
form.submit();
}}} ]});simple.render('d1');}


struts.xml文件  basepackage继承了json-default
<package name="foodpackage" extends="basepackage" namespace="/food">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="toAddFood" class="foodAction" method="toAddFood">
<result name="success" type="tiles">addFoodPage</result>
</action>
<action name="addFood" class="foodAction" method="addFood">
<result name="success" type="tiles">addFoodPage</result>
</action>
<action name="addFoodAjax" class="foodAction" method="addFoodAjax">
<result name="success" type="json">
<param name="includeProperties">success,text</param>
</result>
</action>
</package>

action:
public String addFoodAjax() {
System.out.println("addFoodAjax---start");
System.out.println("" + text);
JSONObject json = new JSONObject();
json.element("success", true);
json.element("text", "登录成功!");
System.out.println(json.toString());
success = true;
text = "ok";
System.out.println("end");
return SUCCESS;
}

其中  JSONObject json = new JSONObject(); 以后的java代码死活也不执行,把
JSONObject json = new JSONObject();
json.element("success", true);
json.element("text", "登录成功!");
System.out.println(json.toString());

这些代码去掉后就能够正常,真不知道为什么。 extjs4
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,