这是注册的reg.jsp界面
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> <%@page import="java.util.List,entity.*"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% request.setCharacterEncoding("UTF-8"); %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录界面</title> <link> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /> <style type="text/css"> * { padding: 0; margin: 0; } .container { margin: 0 auto; width: 100%; height: 100%; } .top, .buttom { height: 300px; width: 100%; } .top { background: black; } h1 { padding-top: 200px; text-align: center; color: white; } h6 { padding-bottom: 10px; text-align: center; color: white; } </style> </head> <body> <% request.setCharacterEncoding("utf-8");//解决中文乱码问题 %> <script type="text/javascript"> <% UsersAction ua = new UsersAction(); List<Users> us = ua.selectAll(); for (int i = 0; i < us.size(); i++) { String DbUser_name = us.get(i).getUser_name(); %> var exist = false; var user_name = document.getElementById("Name").value; if (user_name ==<%=DbUser_name%>) { exist = true } <%}%> if(exist==true){ alert("用户名已经被注册") } </script> <div class="container"> <div class="top form-group"> <h1> Reg Admin<span class="glyphicon glyphicon-cloud"></span> </h1> <h6> <small>powerful backend interface</small> </h6> </div> <div class="buttom"> <form action="RegisterServlet_01" class="form-horizontal" role="form" method="post"> <div class="form-group"> <label for="Name" class="col-sm-4 control-label">姓名:</label> <div class="col-sm-4"> <input type="text" class="form-control" id="Name" placeholder="请输入姓名" name="username"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-4 control-label">密码:</label> <div class="col-sm-4"> <input type="password" class="form-control" id="password" placeholder="请输入密码" name="password"> </div> </div> <div class="form-group"> <div class="col-sm-offset-4 col-sm-4"> <button type="submit" class="btn btn-default">注册</button> </div> </div> </form> </div> </div> <script src="js/JQuery/jquery.min.js"></script> <script src="js/bootstrap.js"></script> </body> </html>
主要我是通过下面这部分想实现该功能的
<script type="text/javascript"> <% UsersAction ua = new UsersAction(); List<Users> us = ua.selectAll(); for (int i = 0; i < us.size(); i++) { String DbUser_name = us.get(i).getUser_name(); %> var exist = false; var user_name = document.getElementById("Name").value; if (user_name ==<%=DbUser_name%>) { exist = true } <%}%> if(exist==true){ alert("用户名已经被注册") } </script>
然后是实体类
UsersAction.java package entity; import java.util.List; public class UsersAction { UsersDao dao = new UsersDao(); public void add(Users users) throws Exception { dao.addUsers(users); } public List<Users> selectAll() throws Exception { return dao.query(); } }
上面两个实体类,一个作为MVC的控制层,一个作为模型层
----------------------------------------------------------------------------------------
下面是用户类
package entity; public class Users { private String user_name; private String password; public Users() { // TODO Auto-generated constructor stub } public String getUser_name() { return user_name; } public void setUser_name(String user_name) { this.user_name = user_name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
ajax大法好
http://www.w3school.com.cn/jquery/ajax_ajax.asp
你应该是登录的时候进行跳转,回来的时候把信息带上,根据具体信息进行提升
我的意思是在不进行跳转的时候进行判断,请问大神有没有指点的地方?
@TimeIsChoice: 那你只能用ajax了
@编程点滴: 还没学,,,我以后试试吧
你可以在后台判断嘛,这个判断是要走数据库的,在后台写判断然后弹出个提示框不就行了
我是想在不提交给后台的情况下进行判断,如果提交给后台用户就会有跳转的视觉感受,我想直接在本页面进行判断,您说的这个我理解,但不是我想要的效果,,,
用ajax