利用jsp+mysql實現(xiàn)好看的登錄與注冊頁面(動態(tài)背景)
效果圖:
需要建立以下五個文件:
在webcontent文件夾下面建立css文件,login.jsp與loginjudge.jsp,registcheck.jsp直接放到webcontent文件夾下面,normalize.min.css與login.css放到css文件里面
數(shù)據(jù)庫我建立的是Td_Snacks,連接數(shù)據(jù)庫賬號和密碼是root,111,不同的請自己修改代碼
建立數(shù)據(jù)庫Td_Snacks
表:user
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `userid` varchar(20) NOT NULL, `username` varchar(8) DEFAULT NULL, `userpwd` varchar(20) DEFAULT NULL, `useremail` varchar(50) DEFAULT NULL, `useraddress` char(100) CHARACTER SET utf8 DEFAULT NULL, `u_profile` varchar(10000) DEFAULT NULL, PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
1.login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title>登錄/注冊</title> <link rel="stylesheet" href="css/normalize.min.css" rel="external nofollow" > <link rel="stylesheet" href="css/login.css" rel="external nofollow" > </head> <script> function check(form){ if(form.user.value == ''){ alert("賬號為空!"); return false; } if(form.password.value == ''){ alert("密碼為空!"); return false; } return true; } function check1(form){ if(form.user1.value == ''){ alert("用戶名為空!"); return false; } if(form.password1.value == ''){ alert("密碼為空!"); return false; } if(form.email1.value == ''){ alert("郵箱為空!"); return false; } if(form.password11.value == ''){ alert("重復(fù)密碼為空!"); return false; } if(form.password1.value !=form.password11.value){ alert("兩次密碼輸入不一致!"); return false; } return true; } </script> <body> <%String newid=request.getParameter("newid"); if(newid==null) newid=" "; %> <div id="formContainer" class="dwo"> <div onclick="javaScript:history.go(-1);" class="return00" >x</div> <div class="formLeft"> <img src="http://img.mp.itc.cn/upload/20170621/3567d2503fe446ceb1ff2b18a9fa8c59_th.jpg"> </div> <div class="formRight"> <!-- Forgot password form --> <form id="forgot" class="otherForm" > <header> <h1>忘記密碼</h1> <p>輸入郵箱找回密碼</p> </header> <section> <label> <p>郵箱</p> <input type="email" placeholder=" " > <div class="border"></div> </label> <button type="submit">發(fā)送郵件</button> </section> <footer> <button type="button" class="forgotBtn">返回</button> </footer> </form> <!-- Login form --> <form id="login" method="post" action="loginjudge.jsp" onSubmit="return check(this);"> <header> <h1>歡迎回來</h1> <p>請先登錄</p> </header> <section> <label> <p>賬號</p> <input type="text" name="id" id="user" autocomplete = "new-password" value=<%=newid%>> <div class="border"></div> </label> <label> <p>密碼</p> <input type="password" placeholder=" " name="pwd" id="password" autocomplete = "new-password"> <div class="border"></div> </label> <button type="submit">登 錄</button> </section> <footer> <button type="button" class="forgotBtn" style="display:none;">忘記密碼?</button> <button type="button" class="registerBtn">新用戶?</button> </footer> </form> <!-- Register form --> <form id="register" class="otherForm" action="registcheck.jsp" onSubmit="return check1(this);"> <header> <h1>用戶注冊</h1> <p>注冊后享受更多服務(wù)</p> </header> <section> <label> <p>用戶名</p> <input type="text" placeholder=" " style="color: black;"name="name" id="user1" autocomplete='off'> <div class="border"></div> </label> <label> <p>郵箱</p> <input type="email" placeholder=" " name="email" id="email1"> <div class="border"></div> </label> <label> <p>密碼</p> <input type="password" placeholder=" " name="pwd" id="password1" autocomplete="new-password"> <div class="border"></div> </label> <label> <p>重復(fù)密碼</p> <input type="password" placeholder=" " id="password11"> <div class="border"></div> </label> <button type="submit">注 冊</button> </section> <footer> <button type="button" class="registerBtn">返回</button> </footer> </form> </div> </div> <div > <ul class="bg-bubbles"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </div> <script src="js/jquery.min.js"></script> <script src="js/script.js"></script> </body> </html>
2.loginjudge.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.sql.*" pageEncoding="utf-8" errorPage="error.jsp"%> <%@ page import = "java.sql.*" %> <!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> </head> <body> <!-- 用戶名密碼合法性、驗證碼驗證(lizhiqiang) --> <!--獲取關(guān)鍵字id(普通用戶:users和商家:shop_owners)--> <% request.setCharacterEncoding("utf-8"); String id= request.getParameter("id");//得到id(登錄界面的文本框內(nèi)容)給id(String) String pwd=request.getParameter("pwd");//得到pwd(登錄界面的文本框內(nèi)容)給pwd(String) System.out.println(id+pwd); session.setAttribute("sessionid",id); //設(shè)置session-sessionid session.setAttribute("sessionpwd",pwd); //設(shè)置session-sessionpwd if(id.equals("admini")&&pwd.equals("admini")){ //管理員登錄 response.setHeader("Refresh","0;url=admin.jsp"); } else{ //非管理員登錄 request.setCharacterEncoding("utf-8"); //數(shù)據(jù)庫連接及判斷 Class.forName("com.mysql.jdbc.Driver");//連接數(shù)據(jù)庫 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Td_Snacks","root","111"); String sql="select * from users where userid ='"+id+"'"; //sql語句,查找普通用戶學(xué)生 String sql1="select * from shop_owners where ownid ='"+id+"'";//sql語句,查找商家 System.out.println(id+pwd+sql+sql1); //輸出到控制臺判斷語句是否正確 Statement stmt = con.createStatement(); Statement stmt2 = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); //普通用戶:學(xué)生結(jié)果集 ResultSet rs1 =stmt2.executeQuery(sql1); //普通用戶:商家結(jié)果集 int result=0; while(rs.next()) //循環(huán)查找普通用戶:學(xué)生結(jié)果集 { String pw=rs.getString("userpwd").trim(); //從結(jié)果集中找到密碼、去掉空格 if(pw.equals(pwd)) //密碼正確 { result=1; //結(jié)果為1 } } while(rs1.next()) //循環(huán)查找普通用戶:商家結(jié)果集 { String pw1=rs1.getString("ownpwd"); //從結(jié)果集中找到密碼 if(pw1.equals(pwd)) //密碼正確 { result=2; //結(jié)果為2 } } stmt.close(); stmt2.close(); con.close(); if(result==1&&id!="admini")//結(jié)果導(dǎo)向 { response.setHeader("Refresh","0;url=index.jsp"); } if(result==2&&id!="admini") { response.setHeader("Refresh","0;url=shop_owner.jsp");//這里放店家 } if(result==0&&id!="admini") { out.println("<script language='javaScript'> alert('賬號或密碼錯誤!');</script>"); out.println("<script language='javascript'>window.location.href='javascript:history.back(-1)'</script>"); } } %> </body> </html>
3.registcheck.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.sql.*" pageEncoding="utf-8" errorPage="error.jsp" import="java.time.LocalDateTime" import="java.time.format.DateTimeFormatter" %> <!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> </head> <body> <!--獲取普通用戶注冊頁面內(nèi)容--> <% request.setCharacterEncoding("utf-8"); String id=LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); String pwd= request.getParameter("pwd");//得到pwd(注冊界面的文本框內(nèi)容)給pwd(String) String name= request.getParameter("name");//得到name(注冊界面的文本框內(nèi)容)給name(String) String email= request.getParameter("email");//得到phone(注冊界面的文本框內(nèi)容)給phone(String) %> <!--數(shù)據(jù)庫連接、判斷及結(jié)果導(dǎo)向--> <% request.setCharacterEncoding("utf-8"); Class.forName("com.mysql.jdbc.Driver");//連接數(shù)據(jù)庫 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Td_Snacks","root","111"); String sql="select * from users where useremail ='"+email+"'"; //sql語句,查找普通用戶學(xué)生 Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); //普通用戶:學(xué)生結(jié)果集 int result=0; if(rs.next()) //循環(huán)查找普通用戶:學(xué)生結(jié)果集 { result=1; //結(jié)果為1 } if(result==1)//普通用戶:學(xué)生表中已存在 { out.println("<script language='javaScript'> alert('該郵箱已被注冊,點擊返回!');window.location='login.jsp'</script>"); } if(result==0) { String sql1="insert into users(userid,userpwd,username,useremail,u_profile) values('"+id+"','"+pwd+"','"+name+"','"+email+"','img/touxiang.jpg')"; stmt.execute(sql1); //執(zhí)行sql1語句,插入到users表 System.out.println(pwd); System.out.println(name); System.out.println(email); %> <script language='javaScript'> alert('注冊成功,您的賬號為:'+<%=id%>+'!');window.top.location='login.jsp?newid='+<%=id%>+''</script> <% response.setHeader("Refresh","0;url=login.jsp"); } stmt.close(); //關(guān)閉數(shù)據(jù)庫連接 con.close(); %> <script>window.open("login.jsp")</script> </body> </html>
4.login.css
* { outline-width: 0; font-family: "Nunito" !important; } input{outline:medium;} input:-internal-autofill-selected { background-color: rgba(119,119,119,0.01) !important; background-image: none !important; box-shadow: inset 0 0 0 1000px rgba(119,119,119,0.01) !important; } input:-webkit-autofill { box-shadow: 0 0 0px 1000px rgba(119,119,119,0.01) inset !important; transition: background-color 50000s ease-in-out 0s; } input:-webkit-autofill:focus { box-shadow: 0 0 0px 1000px rgba(119,119,119,0.01) inset !important; } body { height: 100vh; width: 100vw; background:rgb(255, 128, 128); background: -webkit-linear-gradient(top left, rgb(255, 255, 255) 0%,rgb(255, 128, 128) 100%);/*漸變設(shè)置*/ background: linear-gradient(to bottom right, rgb(255, 255, 255) 0%, rgb(255, 128, 128) 100%); display: flex; justify-content: center; align-items: center; } #formContainer { z-index: 2; display: flex; transition: 0.2s ease; height: 342.5px; transition-delay: 0.3s; } #formContainer.toggle { height: 480px; transition-delay: 0s; } .return00 { z-index: 5; color:#ababab; font-size: 40px; margin:-10px 0px 0px 467px; position: absolute; cursor: pointer; } .return00:hover { color: #8b8378; } .formLeft { background: rgb(255, 249, 249); border-radius: 5px 0 0 5px; padding: 0 35px; box-sizing: border-box; display: flex; align-items: center; } .formLeft img { display: block; width: 72px; border-radius: 50%; box-shadow: 0 5px 5px rgb(255, 128, 128); } .formRight { position: relative; overflow: hidden; border-radius: 0 5px 5px 0; display: flex; flex-direction: column; justify-content: center; } .formRight:before { content: ""; position: absolute; top: -10px; left: -10px; width: calc(100% + 20px); height: calc(100% + 20px); background: url("../images/bg.jpg") center/cover fixed; box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.2); filter: blur(5px); } .formRight form { position: relative; width: 350px; padding: 25px; box-sizing: border-box; white-space: nowrap; overflow: hidden; } .formRight form header { color: #fff; text-align: center; margin-bottom: 15px; } .formRight form header h1 { margin: 0; font-weight: 400; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .formRight form header p { margin: 5px 0 0; opacity: 0.5; font-size: 14px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .formRight form section label { display: block; margin-bottom: 15px; position: relative; } .formRight form section label p { color: #fff; margin: 0 0 10px 0; font-weight: 600; font-size: 12px; opacity: 0.5; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .formRight form section label input { width: 100%; display: block; border: none; background: transparent; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, 0.1); padding: 0 0 10px; box-sizing: border-box; font-weight: 600; } .formRight form section label input:focus~.border { transform: scale(1, 1); } .formRight form section label input:not(:-moz-placeholder-shown)~.border { transform: scale(1, 1); } .formRight form section label input:not(:-ms-input-placeholder)~.border { transform: scale(1, 1); } .formRight form section label input:not(:placeholder-shown)~.border { transform: scale(1, 1); } .formRight form section label .border { position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; background: #fff; transform: scale(0, 1); transition: 0.2s ease; } .formRight form section label:last-child { margin-bottom: 0; } .formRight form section button { background: rgb(255, 202, 202); border: none; width: 100%; padding: 10px 0; font-weight: 600; color: #fff; cursor: pointer; } .formRight form section button:hover { background: rgb(255, 147, 147); } .formRight form footer { margin-top: 15px; display: flex; } .formRight form footer button { background: transparent; padding: 0; border: none; color: #fff; cursor: pointer; font-size: 12px; font-weight: bold; flex: 1; opacity: 0.5; } .formRight form footer button:hover { opacity: 1; } .formRight form.otherForm { top: 0; left: 0; position: absolute; background: rgb(255, 249, 249); height: 100%; z-index: 1; display: flex; flex-direction: column; justify-content: center; width: 0; padding: 25px 0; transition: 0.2s ease; transition-delay: 0.2s; border-left: 1px solid rgba(0, 0, 0, 0.1); } .formRight form.otherForm header { color: #000; opacity: 0; transition: 0.2s ease; transition-delay: 0s; } .formRight form.otherForm p { color: #000; } .formRight form.otherForm section { opacity: 0; transition: 0.2s ease; transition-delay: 0s; } .formRight form.otherForm footer { border-top-color: rgba(0, 0, 0, 0.1); opacity: 0; } .formRight form.otherForm footer button { color: #000; } .formRight form.otherForm input { border-color: rgba(0, 0, 0, 0.1); color: #000; } .formRight form.otherForm .border { background: #000; } .formRight form.otherForm.toggle { width: 100%; padding: 25px; transition-delay: 0s; } .formRight form.otherForm.toggle header, .formRight form.otherForm.toggle section, .formRight form.otherForm.toggle footer { opacity: 1; transition-delay: 0.3s; } .bg-bubbles { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; } .bg-bubbles li { position: absolute; list-style: none; display: block; width: 40px; height: 40px; background-color: rgba(255, 255, 255, 0.15); bottom: 0px; -webkit-animation: square 25s infinite; animation: square 25s infinite; -webkit-transition-timing-function: linear; transition-timing-function: linear; } .bg-bubbles li:nth-child(1) { left: 10%; } .bg-bubbles li:nth-child(2) { left: 20%; width: 80px; height: 80px; -webkit-animation-delay: 2s; animation-delay: 2s; -webkit-animation-duration: 17s; animation-duration: 17s; } .bg-bubbles li:nth-child(3) { left: 25%; -webkit-animation-delay: 4s; animation-delay: 4s; } .bg-bubbles li:nth-child(4) { left: 40%; width: 60px; height: 60px; -webkit-animation-duration: 22s; animation-duration: 22s; background-color: rgba(255, 255, 255, 0.25); } .bg-bubbles li:nth-child(5) { left: 70%; } .bg-bubbles li:nth-child(6) { left: 80%; width: 120px; height: 120px; -webkit-animation-delay: 3s; animation-delay: 3s; background-color: rgba(255, 255, 255, 0.2); } .bg-bubbles li:nth-child(7) { left: 32%; width: 80px; height: 80px; -webkit-animation-delay: 7s; animation-delay: 7s; } .bg-bubbles li:nth-child(8) { left: 55%; width: 20px; height: 20px; -webkit-animation-delay: 15s; animation-delay: 15s; -webkit-animation-duration: 40s; animation-duration: 40s; } .bg-bubbles li:nth-child(9) { left: 25%; width: 10px; height: 10px; -webkit-animation-delay: 2s; animation-delay: 2s; -webkit-animation-duration: 40s; animation-duration: 40s; background-color: rgba(255, 255, 255, 0.3); } .bg-bubbles li:nth-child(10) { left: 90%; width: 80px; height: 80px; -webkit-animation-delay: 11s; animation-delay: 11s; } @-webkit-keyframes square { 0% { -webkit-transform: translateY(0); transform: translateY(0); } 100% { -webkit-transform: translateY(-700px) rotate(600deg); transform: translateY(-700px) rotate(600deg); } } @keyframes square { 0% { -webkit-transform: translateY(0); transform: translateY(0); } 100% { -webkit-transform: translateY(-700px) rotate(600deg); transform: translateY(-700px) rotate(600deg); } }
5.normalize.min.css
button,hr,input{overflow:visible}audio,canvas,progress,video{display:inline-block}progress,sub,sup{vertical-align:baseline}html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0} menu,article,aside,details,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{}button,select{text-transform:none}[type=submit], [type=reset],button,html [type=button]{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:ButtonText dotted 1px}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}[hidden],template{display:none}/*# sourceMappingURL=normalize.min.css.map */
總結(jié)
到此這篇關(guān)于利用jsp+mysql實現(xiàn)好看的登錄與注冊頁面的文章就介紹到這了,更多相關(guān)jsp+mysql登錄與注冊頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
jsp只在首次加載時調(diào)用action實現(xiàn)代碼
如何只在首次加載時調(diào)用action,實現(xiàn)很簡單只需判斷l(xiāng)ist==null即可,感興趣的朋友可以參考下2013-10-10JSP中js傳遞和解析URL參數(shù)以及中文轉(zhuǎn)碼和解碼問題
有關(guān)js傳遞和解析URL參數(shù)以及中文轉(zhuǎn)碼和解碼問題,都是在js中很常見的,下面通過示例簡單為大家介紹下,感興趣的朋友可以參考下2013-10-10jsp中點擊圖片彈出文件上傳界面及預(yù)覽功能的實現(xiàn)
點擊圖片彈出文件上傳界面的效果,想必大家都有見到過吧,在本文為大家詳細(xì)介紹下在jsp中是如何實現(xiàn)的,并對具體的實現(xiàn)代碼做簡要的介紹,感興趣的朋友不要錯過2013-10-10JSP開發(fā)中在spring mvc項目中實現(xiàn)登錄賬號單瀏覽器登錄
這篇文章主要介紹了JSP開發(fā)中在spring mvc項目中實現(xiàn)登錄賬號單瀏覽器登錄的相關(guān)資料,需要的朋友可以參考下2017-05-05