展开全部
下面这是我的登录页面上有关验证码的部分,不知道能不能帮到你!
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
636f70793231313335323631343130323136353331333264643131+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
人力资源管理系统---用户登录type="text/css">
var checkResult = true;
//刷新验证码函数
function reloadcode(){
var verify = document.getElementById('safecode');
verify.setAttribute('src', 'util/CommonImage?a=' + Math.random(+100));
}
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var login = new Ext.FormPanel({
id: 'login',
name: 'login',
labelWidth: 60,
baseCls: 'x-plain', //更改背景
bodyStyle: 'padding:5px 5px 0',
width: 290,
border: false,
defaults: {
width: 170
},
defaultType: 'textfield',//默认字段类型
items: [{
fieldLabel: '用户名',
id: 'username',
name: 'username',
allowBlank: false,//禁止为空
blankText: '用户名不能为空!'
}, {
fieldLabel: '密码',
name: 'userpass',
id: 'userpass',
inputType: 'password',
allowBlank: false,//禁止为空
blankText: '密码不能为空'//可限制多种类型,具体参照api文档
}, {
name: 'chknumber',
id: 'randCode',
fieldLabel: '验证码',
maxLength: 4,
width: 100,
allowBlank: false,
blankText: '验证码不能为空!',
listeners :{
specialKey :function(field,e){
if (e.getKey() == Ext.EventObject.ENTER) submit_login();
}
}
}],
buttons: [{
text: '登录',
handler: submit_login
}, {
text: '重置',
handler: function(){
login.form.reset();
}//重置表单
}]
});
function submit_login(){
var name=Ext.getCmp('username').getValue();
var psw=Ext.getCmp('userpass').getValue();
var code=Ext.getCmp('randCode').getValue();
if (win.getComponent('login').form.isValid()) {
Ext.Ajax.request({
url: '/HRMS/login.do?name='+name+'&psw='+psw+'&code='+code,
method: 'POST',
waitMsg: '正在登录验证,请稍候...',
success: function(response, request){
var msg = Ext.util.JSON.decode(response.responseText);
if(msg.Code==false){
Ext.Msg.alert('操作','验证码输入错误!');
win.getComponent('login').form.reset();
}
else if(msg.Name==false){
Ext.Msg.alert('操作','用户名或密码输入错误!');
win.getComponent('login').form.reset();
}
else if (msg.success==true) {
Ext.Msg.alert('操作','登陆成功');
location.replace("index.jsp");
}else if(msg.success==false){
Ext.Msg.alert('操作','用户名或密码输入错误');
win.getComponent('login').form.reset();
}
},
failure: function(){
Ext.Msg.alert('操作','登陆失败!');
win.getComponent('login').form.reset();
}
});
}
}
win = new Ext.Window({
id: 'win',
title: '登陆',
layout: 'fit',
width: 300,
height: 180,
closeAction: 'close',
closable: false, //控制关闭按钮的显示
plain: true,
buttonAlign: 'center',
items: login
});
win.show();
var bd = Ext.getDom('randCode');
var bd2 = Ext.get(bd.parentNode);
bd2.createChild([{
tag: 'span',
html: ''
}, {
tag: 'img',
id: 'safecode',
src: 'util/CommonImage',
align: 'absbottom'
}]);
});
本回答由提问者推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起