登录注册修改密码
自用备份
登录
<link rel="stylesheet" href="css/style.css">
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<body> <div id="content"> <div class="login-header"> <img src="ico/mall.ico"> </div> <form action="LoginServlet?method=login" method="post"> <div class="login-input-box"> <span class="icon icon-user"></span> <input type="text" name="login_name" placeholder="请输入用户名"> </div> <div class="login-input-box"> <span class="icon icon-password"></span> <input type="password" name="password" placeholder="请输入密码"> </div> <div class="remember-box"> <label> <input type="checkbox"> 记住我 </label> </div> <div class="login-button-box"> <button>登录</button> </div> <div class="logon-box"> <a href="user-reg.jsp">注册</a> <a href="admin-login.jsp">管理员登录</a> </div> </form> </div> </body>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
request.setCharacterEncoding("UTF-8"); String method = request.getParameter("method"); Person_info pi_log = new Person_info(); HttpSession session = request.getSession(); Person_infoBiz biz = new Person_infoBizImpl(); Person_info pi = null; // 登录 if ("login".equals(method)) { String login_name = request.getParameter("login_name"); String password = request.getParameter("password"); String md5pwd = CipherUtil.generatePassword(password); pi_log.setLogin_name(login_name); pi_log.setPassword(md5pwd); biz.login(pi_log); session.setAttribute("pi_log", pi_log); Person_infoBiz pbiz = new Person_infoBizImpl(); pi = pbiz.getLogin(login_name); session.setAttribute("pi", pi); if (pi_log.getUser_id() > 0) { response.sendRedirect("ShowServlet?method=page_list&pageNumber=1"); } else { response.sendRedirect("index.jsp"); }
密码修改
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<body> <a href="ShowServlet?method=page_list">返回</a> <form action="LoginServlet?method=update" method="post"> <input type="hidden" name="user_id" value="${pi.user_id}"> <input type="hidden" name="login_name" value="${pi.login_name}"> <input type="hidden" name="post_id" value="${pi.post_id}"> <input type="hidden" name="other" value="${pi.other}"> <table> <tr> <td>用户名</td> <td>${pi.login_name}</td> </tr> <tr> <td>输入密码</td> <td><input type="password" name="password"></td> </tr> <tr> <td>重复密码</td> <td><input type="password" name="password"></td> </tr> <tr> <td><button type="reset">重置</button></td> <td><button type="submit">提交</button></td> </tr> </table> </form> </body>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
String user_id = request.getParameter("user_id"); String login_name = request.getParameter("login_name"); String password = request.getParameter("password"); String post_id = request.getParameter("post_id"); String other = request.getParameter("other"); String md5pwd = CipherUtil.generatePassword(password); pi_log.setUser_id(Integer.parseInt(user_id)); pi_log.setLogin_name(login_name); pi_log.setPassword(md5pwd); pi_log.setPost_id(Integer.parseInt(post_id)); pi_log.setOther(other); int rs = biz.update(pi_log); if (rs > 0) { response.sendRedirect("success.jsp");
注册
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<body> <div id="content" style="height: 410px;margin-top: 10%" > <div class="login-header"> <img src="ico/reg.ico"> </div> <form action="LoginServlet?method=reg" method="post"> <div class="login-input-box"> <span class="icon icon-user"></span> <input type="text" name="login_name" placeholder="请输入用户名"> </div> <div class="login-input-box"> <span class="icon icon-password"></span> <input type="password" name="password" placeholder="请输入密码"> </div> <div class="login-input-box"> <span class="icon icon-password"></span> <input type="password" name="password" placeholder="请重复密码"> </div> <div class="login-input-box"> <span class="icon icon-password"></span> <input type="text" name="post_id" placeholder="权限"> </div> <div class="login-input-box"> <span class="icon icon-password"></span> <input type="text" name="other" placeholder="备注"> </div> <div class="login-button-box"> <button style="background-color:#F5DEB3;color: black">提交</button> </div> <div class="logon-box"> <a href="index.jsp">返回登录</a> </div> </form> </div> </body>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// 注册 else if ("reg".equals(method)) { String login_name = request.getParameter("login_name"); String password = request.getParameter("password"); String post_id = request.getParameter("post_id"); String other = request.getParameter("other"); String md5pwd = CipherUtil.generatePassword(password); pi_log.setLogin_name(login_name); pi_log.setPassword(md5pwd); pi_log.setPost_id(Integer.parseInt(post_id)); pi_log.setOther(other); int rs = biz.add(pi_log); if (rs > 0) { response.sendRedirect("success.jsp"); return; } else { response.sendRedirect("RegForm.jsp"); return; }