js代码
/**
* ext js 登录
*/
var LoginWindow = Ext.extend(Ext.Window, {
title : "系统登陆",
width : 265,
height : 178,
collapsible : true,
defaults : {
border : false
},
buttonAlign : "center",
createFormPanel : function() {
return new Ext.form.FormPanel({
bodyStyle : "padding-top:6px",
defaultType : "textfield",
labelAlign : "right",
labelWidth : 55,
labelPad : 0,
frame : true,
defaults : {
allowBlank : false,
width : 158
},
items : [{
cls : "user",
name : "username",
fieldLabel : "用户名",
blankText : "用户名不能为空",
msgTarget:"side"
}, {
cls : "key",
name : "password",
fieldLabel : "密码",
blankText : "密码不能为空",
inputType : "password",
msgTarget:"side"
}, {
cls : "rand",
name : "randCode",
id : "randCode",
fieldLabel : "验证码",
width : "80",
blankText : "验证码不能为空"
}]
});
},
login : function() {
this.fp.form.submit({
waitMsg : "正在登陆......",
url : "./sys/login/Login.action",
success : function(form, action) {
window.location.href = "";
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID) {
Ext.MessageBox
.alert("警告", action.result.errors.msg);
}else{
Ext.MessageBox
.alert("登陆失败", action.result.message);
}
}
}
);
},
initComponent : function() {
LoginWindow.superclass.initComponent.call(this);
this.fp = this.createFormPanel();
this.add(this.fp);
this.addButton("登陆", this.login, this);
this.addButton("重置", function() {
this.fp.form.reset();
}, this);
}
});
Ext.onReady(function() {
var win = new LoginWindow();
win.show();
var bd = Ext.getDom("randCode");
var bd2 = Ext.get(bd.parentNode);
bd2.createChild({
tag : "img",
src : "./common/image.jsp",
align : "absmiddle"
});
});
struts配置文件
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="sys" namespace="/sys/login" extends="json-default">
<action name="Login" class="com.mng.sys.login.LoginAction">
<result type="json" />
</action>
</package>