当前位置: 代码迷 >> J2EE >> Extjs3.0整合ssh时提交表单,总是执行failure函数,不知道为什么,请各位指教
  详细解决方案

Extjs3.0整合ssh时提交表单,总是执行failure函数,不知道为什么,请各位指教

热度:155   发布时间:2016-04-22 02:31:13.0
Extjs3.0整合ssh时提交表单,总是执行failure函数,不知道为什么,请各位大虾指教!
本人新手,学习extjs3.0,要把它整合到struts2.1+spring2.5+hibernate3.0的框架中去,想做个添加管理员的功能,可是每次都是调用failure函数还提示错误类型connect,相关代码如下,请各位解答!(本人已经测试过了,如是用jsp做表现层,能把数据写入到数据库而用extjs做表现层则不行)
struts.xml的配置文件如下(action的配置)
XML code
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><package name="json" namespace="/" extends="json-default"><action name="addUser" class="addUser" method="add"><result type="json"/></action></package></struts>    

addUser.action的代码如下:
Java code
package per.ssh.action.admin;import java.io.IOException;import com.opensymphony.xwork2.ActionSupport;import per.ssh.dao.Admin.Admin;import per.ssh.services.admin.adminInterface;public class adminAction extends ActionSupport{    private boolean success;    private String msg="";        /**     * @return the success     */    public boolean isSuccess() {        return success;    }    /**     * @param success the success to set     */    public void setSuccess(boolean success) {        this.success = success;    }    /**     * @return the msg     */    public String getMsg() {        return msg;    }    /**     * @param msg the msg to set     */    public void setMsg(String msg) {        this.msg = msg;    }    private User user;    public User getUser(){        return this.user;    }    public void setUser(User user){        this.user=user;    }    private adminInterface testService=null;    public void setTestService(adminInterface testService){        this.testService=testService;    }    public String add() throws IOException{        Admin admin=new Admin(user.getUserName(),user.getPassword(),Integer.parseInt(user.getUserLevel()));        try{            testService.insert(admin);            success=true;            msg="添加管理员成功!";        }        catch(Exception ex){            success=false;            msg="用户名或密码错误!";        }        System.out.println(user.getUserName()+user.getPassword()+user.getUserLevel());        return SUCCESS;    }}

extjs的代码如下:
JScript code
Ext.ns("per.extjs.userManager");Ext.apply(Ext.form.VTypes,{    confrimPwd:function(val,field){        if(field.initalPassword){            var pwd=Ext.getCmp(field.initalPassword);            return (val==pwd.getValue());        }        return true;    },    confrimPwdText:'两次密码输入不一致!'});per.extjs.userManager.userForm=function(){    var boxStore=new Ext.data.SimpleStore({        fields:['user','level'],        data:[['超级管理员','1'],['一般管理员','2']]    });    var userLevel=new Ext.form.ComboBox({        id:'userLevel',        name:'user.userLevel',        fieldLabel:'用户类别',        forceSelection:true,        triggerAction:'all',        editable:false,        labelWidth:100,        width:125,        store:boxStore,        displayField:'user',        valueField:'level',        mode:'local',        value:'1',        width:600    });    var userName=new Ext.form.TextField({        id:'userName',        name:'user.userName',        fieldLabel:'用&nbsp;户&nbsp;名',        allowBlank:false,        blankText:'用户名不能为空!',        msgTarget:'under',        width:600    });    var password=new Ext.form.TextField({        id:'password',        name:'user.password',        fieldLabel:'用户密码',        allowBlank:false,        blankText:'密码不能为空',        inputType:'password',        msgTarget:'under',        width:600    });    var confrimPassword=new Ext.form.TextField({        id:'cpwd',        name:'cpwd',        fieldLabel:'重复密码',        inputType:'password',        initalPassword:'password',        vtype:'confrimPwd',        allowBlank:false,        blankText:'重复密码不能为空',        msgTarget:'under',        width:600    });     per.extjs.userManager.userForm.superclass.constructor.call(this,{        id:'userForm',        title:'添加管理员',        frame:true,        autoHeight:true,        applyTo:'main',        labelAlign:'right',        buttonAlign:'center',        labelWidth:'100',        width:760,        collapsible:true,        animCollapse:true,        bodyStyle:'padding:5px;',        items:[        {            xtype:'fieldset',            title:'管理员信息',            autoHeight:true,            autoWidth:true,            items:[userLevel,userName,password,confrimPassword]        }        ],        buttons:[        {            text:'提交',            handler:submit        },{            text:'取消',            handler:reset        }        ]    });    function submit(){        Ext.getCmp('userForm').form.submit({            clientValidation:true,            //waitMsg:'正在提交数据,请稍等...',            //waitTitle:'提示',            url:'addUser.action',            method:'POST',            //params:{userLevel:userComboBox,userName:userName,password:userpassword},            success:function(form,action){                Ext.Msg.alert('提示',"添加管理员成功!");            },            failure:function(form,action){                Ext.Msg.alert('提示',action.failureType+":"+action.getUrl());            }        });    }    function reset(){        Ext.getCmp('userForm').form.reset();    }}Ext.extend(per.extjs.userManager.userForm,Ext.form.FormPanel,{});
  相关解决方案