</pre><p>jsp页面:</p><p> <span style="white-space:pre"> </span><pre name="code" class="html"><div class="center_login_mid">
<ul>
<li>
<label>手机:</label>
<input type="text" class="login_tel"/>
<p class="alert_infor" ><span>*</span>请输入你注册的手机号</p>
</li>
<li>
<label>密码:</label>
<input type="password" class="login_pass"/>
</li>
</ul>
</div>
<div class="regist_btn">
<a class="login_button">登录</a>
<a href="index.jsp" class="regist_cancel">取消</a>
</div>
</div>
$('.login_button').click(function(){
var login_tel=$('.login_tel').val();
var login_pass=$('.login_pass').val();
if(!login_tel){
$('.login_error').html("* 手机号为空,这样真的好吗?");
return false;
}
if(!login_tel.match(/^[1]{1}[0-9]{10}$/)){
$('.login_error').html("* 输入的手机号码格式不正确,这样真的好吗?");
return false;
}
if(!login_pass){
$('.login_error').html("* 密码为空,这样真的好吗?");
return false;
}
$.ajax({
type:'post',
url:'/wemiss/login.action',
data:{
"logintool.phonenum": login_tel,
"logintool.pass": login_pass
},
success:function(data){
if(data=="fail"){
window.location="/wemiss/manager/login.jsp";
}else{
window.location="/wemiss/manager/login_success.jsp";
}
}
})
})
后台java代码:
public String login(){
logindata=allservice.login(logintool);
if(logindata!=null){
try {
response.getWriter().write("success");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("登录成功");
this.session.setAttribute("username", logindata.username);
}else{
try {
response.getWriter().write("fail");
System.out.println("登录失败");
this.session.setAttribute("loginerror", "* 用户名或密码输入错误,请重新输入");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}