注册验证是可以正常进入服务器并于controller中的checkRegister交互的,并且控制台能输出sql语句。但是登录却不行,检查很多遍没发现写错什么,但是并没有进入到checkLogin方法,连方法内部的systemout一个都没输出来。最让我不解的是,用谷歌和ie浏览器时,不进对应的方法不说,内存占用逐渐上升飙红了,网页关掉就恢复正常。而这些问题,注册页面统统没有。。我查来查去真不知道是什么原因了,请各位大神帮忙指点分析一下。下面贴上源码登录的JS:<script type="text/javascript" src="<%=path %>/statics/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input").blur(function(){
var ele=$(this);
var getValue=ele.val();//获取创建用户时输入的文本信息
if($(this).is("#cardId")){
var reg=/^\d{18,18}$/;
if(reg.test(getValue)==false){
flag=false;
ele.attr("style","color:red;border:1px solid red;");
ele.next().attr("style","color:red;").html(" 账号输入有误!");
}else{
ele.attr("style","color:green;border:1px solid green");
ele.next().attr("style","color:green;").html(" 账号输入正确!");
}
}else if($(this).is("#password")){
var reg=/^\w{6,}$/;
if(reg.test(getValue)==false){
ele.attr("style","color:red;border:1px solid red;");
ele.next().attr("style","color:red;").html(" 密码输入有误!");
}else{
ele.attr("style","color:green;border:1px solid green");
ele.next().attr("style","color:green;").html(" 密码输入正确!"); }
}
});
$("form").submit(function(){
alert(1);
var result=false;
var cardId=$("#cardId");
var password=$("#password");
$.ajax({
async:false,
url:"<%=path%>/users/checkLogin",
type:"post",
data:{"cardId":cardId,"password":password},
dataType:"json",
success:function(data,xstatus,xhr){
if(data==1){
alert("该账号不存在,请先注册!")
}else if(data==2){
alert("登录失败,账号密码不匹配!")
}else if(data==3){
alert("登录失败,该账号已冻结!")
}else if(data==0){
result=true;
}
},
error:function(){
alert(4);
}
});
return result;
});
});
</script>登录的JSP中HTML表单: <body>
<sp:form modelAttribute="users" action="/users/login" method="POST">
<div align="center">
<h2>房产信息查询系统</h2>
<table>
<tr><td>请输入身份证号</td><td><sp:input path="cardId" /><span/></td></tr>
<tr><td>请输入密码</td><td><sp:input path="password" /><span/></td></tr>
</table>
<tr><td><input type="submit" value="登录" /></td><td><a href="<%=basePath%>users/register">注册</a></td></tr>
</div>
</sp:form>
</body>登录与注册的后端处理:@Controller
@RequestMapping(value="/users")
public class UserController{
@Resource
private IUsersService usersService;
private Map<Integer,Users> usersList;
//用户登录
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model){
Users users=new Users();
model.addAttribute(users);
return "_login";
}
@RequestMapping(value="/login",method=RequestMethod.POST)
public String login(Users users,Model model){
model.addAttribute("users",users);
return "viewIndex";
}
@RequestMapping(value="/checkLogin",method=RequestMethod.POST)
public void checkLogin(HttpServletRequest request,
HttpServletResponse response,Users user,Model model){
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String cardId = request.getParameter("cardId");
System.out.println(cardId);
String pw=request.getParameter("password");
System.out.println(pw);
Users u=usersService.getUserByCardId(cardId);
String message=null;
if(u==null||!cardId.equals(u.getCardId())){
message="[1]";//该账号不存在,请先注册!
System.out.println("该账号不存在,请先注册");
}else if(!cardId.equals(u.getCardId())||!pw.equals(u.getPassword())){
message="[2]";//登录失败,身份证号或密码错误!
System.out.println("登录失败,身份证号或密码错误!");
}else if(u.getStatus()==0){
message="[3]";//登录失败,该账号已被冻结!
System.out.println("登录失败,该账号已被冻结!");
}else{
message="[0]";
System.out.println("登录成功。。。");
}
PrintWriter out= response.getWriter();
out.write(JSONArray.fromObject(message).toString());
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//用户注册
@RequestMapping(value="/register",method=RequestMethod.GET)
public String register(Model model){
Users users=new Users();
model.addAttribute(users);
return "_register";
}
@RequestMapping(value="/register",method=RequestMethod.POST)
public String register(Users users,Model model){
Integer gender=new Integer(users.getCardId().substring(17));
if(gender%2==0)gender=0;else gender=1;
users.setGender(gender);
Date createTime=new Date(System.currentTimeMillis());
users.setCreateTime(createTime);
users.setStatus(1);
usersService.insertUsers(users);
return "_login";
}
//注册验证
@RequestMapping(value="/checkRegister",method=RequestMethod.POST)
public void checkRegister(HttpServletRequest request,
HttpServletResponse response,Users user,Model model){
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String message=null;
String id = request.getParameter("cardId");
Users u=usersService.getUserByCardId(id);
if(u==null){
message="[0]";//代表可以注册
}else{
message="[1]";//代表已存在
}
PrintWriter out= response.getWriter();
out.write(JSONArray.fromObject(message).toString());
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}注册的JS:<script type="text/javascript" src="<%=path %>/statics/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input").blur(function(){
var ele=$(this);
var flag=true;
var getValue=ele.val();//获取创建用户时输入的文本信息
if($(this).is("#cardId")){
var reg=/^\d{18,18}$/;
if(reg.test(getValue)==false){
flag=false;
ele.attr("style","color:red;border:1px solid red;");
ele.next().attr("style","color:red;").html(" 请输入正确的身份证号码");
}else{
$.ajax({
async:false,
url:"<%=path%>/users/checkRegister",
type:"post",
data:{"cardId":getValue},
dataType:"json",
success:function(data,xstatus,xhr){
if(data==1){
flag=false;
ele.attr("style","color:red;border:1px solid red");
ele.next().attr("style","color:red").html(" 此身份证已注册!");
return;//此处return和break效果相同
}else{
flag=true;
ele.attr("style","color:green;border:1px solid green");
ele.next().attr("style","color:green;").html(" 此身份证可以注册!");
}
},
error:function(){
alert(4);
}
});
}
}else if($(this).is("#name")){
var reg=/^\w{6,25}$/;
if(reg.test(getValue)==false){
flag=false;
ele.attr("style","color:red;border:1px solid red;");
ele.next().attr("style","color:red;").html(" 用户名格式错误");
}else{
flag=true;
ele.attr("style","color:green;border:1px solid green");
ele.next().attr("style","color:green;").html(" 用户名格式正确"); }
}
else if($(this).is("#password")){
var reg=/^\w{6,}$/;
if(reg.test(getValue)==false){
flag=false;
ele.attr("style","color:red;border:1px solid red;");
ele.next().attr("style","color:red;").html(" 密码格式错误");
}else{
flag=true;
ele.attr("style","color:green;border:1px solid green");
ele.next().attr("style","color:green;").html(" 密码格式正确"); }
}
else if($(this).is("#confirmpassword")){
var reg=/^\w{6,}$/;
if(reg.test(getValue)==true&&getValue==$("#password").val()){
flag=true;
ele.attr("style","color:green;border:1px solid green;");
ele.next().attr("style","color:green;").html(" 密码格式正确");
}else{
flag=false;
ele.attr("style","color:red;border:1px solid red");
ele.next().attr("style","color:red;").html(" 密码格式错误"); }
}
});
$("form").submit(function(){
if(flag=true){
event.returnValue=confirm("注册已成功,现在去登录吗!")
}
});
});
</script>注册的JSP中HTML表单:<body>
<sp:form modelAttribute="users" action="/users/register" method="POST">
<div align="center">
<h2>账号注册</h2>
<table>
<tr><td>身份证号</td><td><sp:input path="cardId" /><span/></td></tr>
<tr><td>用户名</td><td><sp:input path="name" /><span/></td></tr>
<tr><td>密码</td><td><sp:input path="password" /><span/></td></tr>
<tr><td>确认密码</td><td><sp:input path="confirmpassword" /><span/></td></tr>
</table>
<tr><td><input type="submit" value="注册" /></td><td><input
type="button" value="返回" onclick="history.go(-1)" /></td></tr>
</div>
</sp:form>
</body>
- 3 回答
- 0 关注
- 12547 浏览
添加回答
举报
0/150
提交
取消