当前位置: 代码迷 >> Ajax >> ajax的登录印证
  详细解决方案

ajax的登录印证

热度:132   发布时间:2016-05-11 09:10:24.0
ajax的登录验证

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" onclick="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("输入的用户名,密码有错误");
}
});

   

  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Tue Feb 28 20:18:38 CST 2017
  • 最近登录:Tue Feb 28 20:18:38 CST 2017
  • 最近登录:Tue Feb 28 20:18:38 CST 2017
  • 最近登录:Tue Feb 28 20:18:38 CST 2017
  • 最近登录:Tue Feb 28 20:18:38 CST 2017