81,092
社区成员
发帖
与我相关
我的任务
分享
LoginForm lf = (LoginForm)form;
response.setContentType("text/json;charset=utf-8");
//System.out.println(lf.getUsername()+lf.getPassword());
PrintWriter out;
try {
out = response.getWriter();
String jsonStr="";
//业务处理
if("admin".equals(lf.getUsername().trim()) && "admin".equals(lf.getPassword().trim())){
jsonStr="{success:true,msg:'ok'}";
}else{
jsonStr="{success:true,msg:'no'}";
}
out.print(jsonStr);
System.out.println(jsonStr);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
success:function(response){
var jsonObj=Ext.decode(response.responseText);
if(jsonObj.msg=="ok"){
window.location.href='main.html'
}
else{
alert(jsonObj.msg);
}
},
var loginForm = new Ext.FormPanel({
title : "登录",
frame : true,
bodyStyle : 'padding-left: 10px;padding-top: 10px;',
width : 410,
height : 220,
items : [{
layout : 'column',
items : [{
columnWidth : .45,
html : '<img src="images/login/login_title.gif" />' // 左边列放一个logo
}, {
columnWidth : .55,
bodyStyle : 'padding-left: 5px;padding-top:30px;',
labelPad : 0,
labelWidth : 45,
items : [{
xtype : 'fieldset',
collapsible : false,
baseCls : "x-fieldset",
width : 200,
height : 120,
defaultType : 'textfield',
items : [{
cls : 'user',
fieldLabel : '用户名',
id : 'login-username',
name : 'username',
allowBlank : false,
// 不允许为空
value : jty.util.getCookie("username"),
blankText : '用户名不能为空',
anchor : '95%'
}, {
cls : 'key',
fieldLabel : '密 码',
id : 'login-password',
name : 'password',
allowBlank : false,
// 不允许为空
blankText : '密码不能为空',
value : "",
inputType : 'password',
anchor : '95%'
}],
buttons : [{
text : '登录',
type : 'submit',
handler : loginAction
}, {
text : '关闭',
handler : function() {
window.open("", "_parent", "");
window.close();
}
}]
}]
}]
}]
});
loginForm.render("login");
loginForm.el.center();
function loginAction() {
// 验证是否合法
if (!loginForm.form.isValid()) {
// Ext.MessageBox.alert('验证错误', '页面验证有错误!');
return;
}
loginForm.form.doAction('submit', {
url : 'login.action',
// 文件路径
method : 'post',
// 提交方法post或get
params : '',
// 提交成功的回调函数
success : function(form, action) {
document.location = 'index.action';
},
// 提交失败的回调函数
failure : function(form, action) {
// form.reset();
Ext.MessageBox.alert('登录错误', action.result.message);
}
});
}
点击超链接的时候,显示登陆的window或是formPanel。显示模式设置成遮罩,遮罩后就不能操作后面的业务了。登陆成功后,隐藏window或formPanel即可。