日期:2014-05-17  浏览次数:20621 次

S2SH、EXTJS、JSON整合后,EXTJS接收不到Struts2的Action传回的值,无语!
EXTJS
JScript code

Ext.onReady(function(){
    var f = new Ext.form.FormPanel({
            //数据传送到服务器的配置
        url: "/BackOS/login.action",
        method: "post",
//        baseParams: {extra: "中华人民共和国", id: 100},
        title: "欢迎登陆",
        width: 300,
        autoHeight: true,
        bodyStyle: "padding: 6px",
        labelAlign: "right",
        defaultType: "textfield",//默认组件类型
        frame: true,
        items: [
            new Ext.form.TextField({
                name: "teller.tellerno",
                allowBlank: false, //不允许为空
                value: "000000",
                fieldLabel: "用户名"
            }),{
                name: "teller.password",
                inputType: "password",
                value: "123456",
                fieldLabel: "密码",
                allowBlank: false //不允许为空
            }
        ],
        buttons:[{
            text: "确定",
            handler: function(){
                var userName = f.getForm().findField("teller.tellerno").getValue();
                var password = f.getForm().findField("teller.password").getValue();
//                Ext.Msg.alert("", "用户名:" + userName + "<br>密码:" + password);
            
                //提交表单
                f.getForm().submit({
                    success: function(f, action){
                        Ext.Msg.alert("",action.responseText);
//                        Ext.Msg.alert("成功", "恭喜,表单提交成功,服务器反馈的结果是:");
                    },
                    failure: function(){
                        Ext.Msg.alert("失败", "对不起,表单提交失败");
                    }
                });
            }
        },
        {
            text: "重置",
            handler: function(){
                //f.getForm().reset();
                var fields = f.getForm().items.items;
                for(var i = 0; i < fields.length; i ++){
                    fields[i].reset();                    
                }
            }
        }]
    });
    
    f.render("login");
})


Struts2 Action
Java code

public String execute() throws Exception {
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("text/html;charset=utf-8");
        if(itt.userLogin(teller)){
            System.out.println("-------------1");
            response.getWriter().println("{success:'true'}");
            return SUCCESS;
        }
        else{
//            response.getWriter().println("{success:false,msg:'失败登陆'}");
            return SUCCESS;
        }
    }


struts.xml配置
XML code

<package name="nothing" extends="json-default">
        <default-action-ref name="login" />
        <action name="login" class="loginAction">
            <result type="json"></result>
        </action>
    </package>


点击登陆后控制台打印信息
Hibernate: 
  select
  tphonetell0_.tellerno as tellerno0_,
  tphonetell0_.tellername as tellername0_,
  tphonetell0_.password as password0_,
  tphonetell0_.bankno as bankno0_,
  tphonetell0_