ajax的登录验证

[color=blue]
1.login.jsp
<form id="form1" name="form1" action="login.action" method="post">
<center>

<table cellSpacing=10px >
<tr>
<td>取引CD</td>
<td><input id="cd" name="takeCd" type="text"
style="width: 150px" /></td>
</tr>
<tr>
<td>userId</td>
<td><input id="userId" name="id" maxlength="6" type="text"
style="width: 150px" /></td>
</tr>
<tr>
<td>passWord</td>
<td><input id="passWord" name="pass" type="password"
style="width: 150px" /></td>
</tr>

</table>

<br>

<input type="button" value="ログイン" name="press" οnclick="check();" /></center>
<input type="hidden" name="flag" id="flag" value="" />
</form>

struts.xml

<action name="loginPass" class="LoginAction" method="checkPassWord">

</action>

spring.xml里面配置javaBean

<bean name="LoginAction" class="jp.co.syspro.action.LoginAction">
<property name="kintaiService" ref="kintaiService" />
</bean>


然后在Action里面写验证代码:

public String checkPassWord() throws Exception{

String id=this.getRequest().getParameter("id");
String pwd=this.getRequest().getParameter("pwd");
String result="";
Map mapAjax= new HashMap();
mapAjax.put("id", id);
mapAjax.put("pwd", pwd);
TblEmpVO to=this.kintaiService.getEmpCd(mapAjax);
if(to!=null){
result="success";
}else{
result="false";
}
this.getResponse().setContentType("html/text charset=utf-8");
PrintWriter pw = this.getResponse().getWriter();
pw.write(result);
pw.flush();
pw.close();
return null;
}


然后再1.login.jap页面中 :
$.get(url,function(result){
var a=result;
var flg= document.getElementById("flag");
var f=document.getElementById("form1");
if(a=="success"){
if(takeCd=="025450"){
flg.value="0";
f.submit();
}else{
flg.value="1";
f.submit();
}
}else if(a=="false"){
alert("输入的用户名,密码有错误");
}
});



[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值