日期:2014-05-20 浏览次数:20726 次
<?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>
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; } }
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:'用 户 名', 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,{});