900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Javascript注册页面验证登录

Javascript注册页面验证登录

时间:2024-03-23 16:51:39

相关推荐

Javascript注册页面验证登录

Javascript注册页面验证登录连接数据库。

目前登录功能好像出问题了,用不了数据库注册的信息用于登录。由于时间的原因,以后再更改。个人笔记,不建议拿去用,因为还存在问题没有解决。

(1)index.css

@CHARSET "UTF-8";header {width: 800px;height: 50px;background:rgba(218,80,223,0.70);margin: 0 auto;color: white;text-align: center;border:1px solid #FFF;/*添加边框*/}nav {width: 800px;height: 30px;color: white;background:rgba(350,80,201,0.60);text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/}section {margin: 0 auto;width: 800px;height: 450px;color: white;text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/}aside {float: left;width: 200px;height: 450px;background:rgba(25,215,206,0.40);color: black ;text-align: center;margin: 0 auto;}article {float: right;height: 450px;width: 600px;color: white;border:1px solid #FFF;/*添加边框*/text-align: center;background:rgba(239,68,195,0.40);margin: 0 auto;}footer {width: 800px;height: 50px;background:rgba(218,80,223,0.60);color: white;text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/}a {a{display: block;/*将a变成块状*/width: 100px;/*设置块的宽度*/height: 50px;/*设置块的长度*/font-family: Microsoft Yahei;line-height: 50px;/*设置字体在块中的高度#*/background-color:rgba(151,16,113,0.40) ;margin: 0px 0px;/*块里的高宽通过margin设置*/color: #fff;text-align: center;/*字体居中*/text-decoration: none;/*去掉下划线*/font-size: 15px;}}p {text-align: center;}legend {text-align: center;}

(2)index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>学生信息管理系统首页</title><link rel="stylesheet" type="text/css" href="index.css" /></head><body id="body" background=""><div id="header"><h3>学生信息管理首页</h3></div><ul id="nav"> <li><a href="index.jsp" >首页</a></li><li><a href="regist.jsp">注册</a></li><li><a href="login.jsp">登录</a></li><li><a href="alarm.jsp">学生信息</a></li></ul><!-- 中间 --><div id="content"><h1>使用学生信息管理系统! </h1></div><!--底部--><div id="footer"></div></body></html>

(3)login.css

@CHARSET "UTF-8";#body{width: 800px;height:auto;margin: 0 auto;color: rgba(0,0,0,1.00);text-align: center;border:1px solid #000000;/*添加边框*/}#header{width: 800px;height: 50px;background:rgba(218,80,223,0.70);margin: 0 auto;color: rgba(0,0,0,1.00);text-align: center;border:1px solid #FFF;/*添加边框*/border-right:1px solid #000000;background-color:skyblue;/*设置透明背景颜色*/}#nav {Width:800px; height:40px;padding:0;margin: 0 auto;list-style:none; background-color: rgba(197,92,207,1.00);} #nav li {width:150px;height:40px;float:left;text-align:center;border-bottom:solid 1px rgba(244,244,244,1.00);border-right:solid 1px rgba(244,244,244,1.00);font:25px "microsoft yahei";}#nav li a {width:150px;height:40px;color:#800080; line-height: 50px;text-decoration:none;} #nav li a:hover{width:150px;height:40px;display:block; background-color:blue;}#content{margin: 0 auto;width: 800px;height: auto;text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/border-right:1px solid #000000;color: rgba(0,0,0,1.00);background-color:white;}.aaa{text-align-last:justify;display: inline-block; width: 80px;}.bbb{align:center;margin-top:20px;}.ccc{background-color:skyblue;display: block;align:center;width: 400px;height: auto;margin-left: 200px;margin-top: 30px;margin-bottom: 40px;border:1px solid #000;}.ddd{background-color: rgba(208,162,63,1.00);}#footer {width: 800px;height: 50px;background:rgba(218,80,223,0.60);text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/background-color:skyblue;border-right:1px solid #000000;}#a{text-decoration:none;}

(4)login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>登录页面</title><link rel="stylesheet" type="text/css" href="login.css" /><script type="text/javascript"></script></head><body id="body" background=""><div id="header"><h3>学生信息管理系统登录页面</h3></div><ul id="nav"> <li><a href="index.jsp" >首页</a></li><li><a href="regist.jsp">注册</a></li><li><a href="login.jsp">登录</a></li><li><a href="alarm.jsp">学生信息管理</a></li></ul><!-- 中间 --><div id="content"><h1>欢迎登录学生信息管理系统</h1><div class="ccc"><h3>请登录...</h3><h4>登录</h4><form action="${pageContext.request.contextPath}/loginServlet" method="post"><div class="bbb"><label class="aaa">用户名:</label><input type="text" id="username" name="username" placeholder="请输入用户名" /></div><br /><div class="bbb"><label class="aaa">密码:</label><input type="password" id="password" name="password" placeholder="请输入密码"/></div><br /><div class="bbb"><input type="checkbox" value="记住用户名" checked />记住用户名</div><br /><div class="bbb"><input class="ddd" type="submit" id="login" name="login" value="登录" /><a href="${pageContext.request.contextPath}/regist.jsp" class="a">账号注册</a></div><br /></form></div></div><!--底部--><div id="footer"></div></body></html>

(5)regist.css

@CHARSET "UTF-8";#body{width: 800px;height:auto;margin: 0 auto;color: rgba(0,0,0,1.00);text-align: center;border:1px solid #000000;/*添加边框*/}#header{width: 800px;height: 50px;background:rgba(218,80,223,0.70);margin: 0 auto;color: rgba(0,0,0,1.00);text-align: center;border:1px solid #FFF;/*添加边框*/border-right:1px solid #000000;background-color:skyblue;/*设置透明背景颜色*/}#nav {Width:800px; height:40px;padding:0;margin: 0 auto;list-style:none; background-color: rgba(197,92,207,1.00);} #nav li {width:150px;height:40px;float:left;text-align:center;border-bottom:solid 1px rgba(244,244,244,1.00);border-right:solid 1px rgba(244,244,244,1.00);font:25px "microsoft yahei";}#nav li a {width:150px;height:40px;color:#800080; line-height: 50px;text-decoration:none;} #nav li a:hover{width:150px;height:40px;display:block; background-color:blue;}#content{margin: 0 auto;width: 800px;height: auto;text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/border-right:1px solid #000000;color: rgba(0,0,0,1.00);background-color:white;}.aaa{text-align-last:justify;display: inline-block; width: 80px;}.bbb{align:center;margin-top:20px;}.ccc{background-color:pink;display: block;align:center;width: 400px;height: auto;margin-left: 200px;margin-top: 30px;margin-bottom: 40px;border:1px solid #000;}.ddd{background-color: rgba(208,162,63,1.00);}#footer {width: 800px;height: 50px;background:rgba(218,80,223,0.60);text-align: center;margin: 0 auto;border:1px solid #FFF;/*添加边框*/background-color:skyblue;border-right:1px solid #000000;}

(6)regist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>注册页面</title><link rel="stylesheet" type="text/css" href="regist.css" /></head><body id="body" background=""><div id="header"><h3>学生信息管理系统注册页面</h3></div><ul id="nav"> <li><a href="index.jsp" >首页</a></li><li><a href="regist.jsp">注册</a></li><li><a href="login.jsp">登录</a></li><li><a href="alarm.jsp">学生信息</a></li></ul><!-- 中间 --><div id="content"><h1>欢迎注册学生信息管理系统</h1><div class="ccc"><h3>用户注册</h3><p>欢迎注册您的相关信息,请您如实填写</p><form action="${pageContext.request.contextPath}/registServlet" method="post"><div class="bbb"><label class="aaa" >用户姓名: </label><input type="text" name="username" id="username" placeholder="请输入学号"/> <br/></div><div class="bbb"><label class="aaa" >手机号码:</label><input type="tel" name="userphone" id="userphone" pattern="^1\d{10}$" placeholder="请输入手机号" /><br/></div><div class="bbb"><label class="aaa" >邮箱地址:</label><input type="email" name="email" id="email"/><br/></div> <div class="bbb"><label class="aaa" for="password">密码: </label><input type="password" name="password" id="pwd"placeholder="请输入密码" /> <br /></div><div class="bbb"><label class="aaa" for="password1">确认密码: </label><input type="password" name="password1" id="repwd" placeholder="再次输入密码" /> <br/></div><font color="red" size="2"> ${registError }</font><div class="bbb"><input type="checkbox" checked />我同意<a href="#">相关协议和政策</a><br /></div><div class="bbb"><input class="ddd" type="submit" id="checksubmit" value="提交" /> <input class="ddd" type="reset" value="重置" /><a href="${pageContext.request.contextPath}/login.jsp" class="signup-link">已有账号?返回登录</a></div></form></div></div><!--底部--><div id="footer"></div></body></html>

(7)loginSevlet.java

package servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import DAO.UserDao;import student.UserVo;/*** @description 登录请求处理类* @author LLM*/@WebServlet("/loginServlet")public class loginServlet extends HttpServlet {private static final long serialVersionUID = 1L;@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");//接收表单信息String username = request.getParameter("username");String password = request.getParameter("password");//设置回显request.setAttribute("username", username);request.setAttribute("password", password);//根据用户名查询用户UserVo user =new UserDao().findUser(username);//查找数据库是否有相应的用户密码。验证登录if(user!=null){if(user.getPassword().equals(password)){request.getSession().setAttribute("user", user);response.sendRedirect("loginsuccess.jsp");}else if(password==null||!user.getPassword().equals(password)) {response.sendRedirect("loginfail.jsp");}else if(username==null){response.sendRedirect("loginfail.jsp");}}else {response.sendRedirect("loginfail.jsp");}}@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);}}

(8)registeServlet.java

package servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import DAO.UserDao;import student.UserVo;/*** @description 注册请求处理类* @author WANGZIC*/@WebServlet("/registServlet")public class registServlet extends HttpServlet {private static final long serialVersionUID = 1L;@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");//从regist.jsp获取表单信息String username = request.getParameter("username");String userphone= request.getParameter("userphone");String email = request.getParameter("email");String password = request.getParameter("password");String rpsw = request.getParameter("password1");//验证注册if(username==null||username.trim().isEmpty()){request.setAttribute("registError", "用户名不能为空");request.getRequestDispatcher("/regist.jsp").forward(request, response);return;}if(userphone==null||userphone.trim().isEmpty()){request.setAttribute("registError", "电话号码不能为空");request.getRequestDispatcher("/regist.jsp").forward(request, response);return;}if(email==null||email.trim().isEmpty()){request.setAttribute("registError", "邮箱不能为空");request.getRequestDispatcher("/regist.jsp").forward(request, response);return;}if(password==null||password.trim().isEmpty()){request.setAttribute("registError", "密码不能为空");request.getRequestDispatcher("/regist.jsp").forward(request, response);return;}if(!password.equals(rpsw)){request.setAttribute("registError", "密码不一致");request.getRequestDispatcher("/regist.jsp").forward(request, response);return;}UserDao u = new UserDao();//增加数据到数据库boolean res = u.addUser(username,userphone,email,password);if(res){response.sendRedirect("registsuccess.jsp");System.out.println("增加用户到数据库成功");}else {request.setAttribute("registError", "注册失败,该用户名已存在");request.getRequestDispatcher("/regist.jsp").forward(request, response);System.out.println("增加用户到数据库成功");}}@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);}}

(9)UserVo.java(这是一个Javabean类)

package student;public class UserVo {private int id;private String username;private String userphone;private String email;private String password;public int getId(){return id;}public String getUsername(){return username;}public String getUserphone(){return userphone;}public String getEmail(){return email;}public String getPassword(){return password;}public void setId(int id){this.id=id;}public void setUsername(String username){this.username=username;}public void setUserphone(String userphone){this.userphone=userphone;}public void setEmail(String email){this.email=email;}public void setPassword(String password){this.password=password;}public String toString() {return "查询结果:User{" +"id=" + id +", username='" + username + '\'' +", userphone='" + userphone + '\'' +", email='" + email + '\'' +", password='" + password + '\'' +'}';}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。