日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

密码登录源码(jsp+java+数据库)

發布時間:2025/4/16 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 密码登录源码(jsp+java+数据库) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

jsp界面:

<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="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"> </head> <style type="text/css"> #code { font-family:Arial; font-style:italic; font-weight:bold; border:0; letter-spacing:2px; color:blue; } </style> <body > <%Object message = request.getAttribute("message");if(message!=null && !"".equals(message)){%><script type="text/javascript">alert("<%=request.getAttribute("message")%>");</script> <%} %><div align="center"><h1 style="color: red;">登陸界面</h1><form action ="Servlet?method=login" method="post" οnsubmit="return check()"><div><div >賬號<input type="text" id="a" name="name"/></div><div >密碼<input type="password" id="b" name ="password" placeHolder='password'/></div><p> <input type = "text" id = "input"/> <input type = "button" id="code" οnclick="createCode()"/> <input type = "button" value = "驗證" onclick = "validate()"/> </p> <input type="submit" value="登錄"><a href="add.jsp" >注冊</a></div></form></div><script type="text/javascript">function check(){var a = document.getElementById("a");var b= document.getElementById("b");if(a.value==""){alert('賬號為空');a.focus();return false;}if(b.value==""){alert('密碼為空');a.focus();return false;}}var code ; //在全局定義驗證碼 //產生驗證碼 window.onload = function createCode(){ code = ""; var codeLength = 4;//驗證碼的長度 var checkCode = document.getElementById("code"); var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', 'S','T','U','V','W','X','Y','Z');//隨機數 for(var i = 0; i < codeLength; i++) {//循環操作 var index = Math.floor(Math.random()*36);//取得隨機數的索引(0~35) code += random[index];//根據索引取得隨機數加到code上 } checkCode.value = code;//把code值賦給驗證碼 } //校驗驗證碼 function validate(){ var inputCode = document.getElementById("input").value.toUpperCase(); //取得輸入的驗證碼并轉化為大寫 if(inputCode.length <= 0) { //若輸入的驗證碼長度為0 alert("請輸入驗證碼!"); //則彈出請輸入驗證碼 } else if(inputCode != code ) { //若輸入的驗證碼與產生的驗證碼不一致時 alert("驗證碼輸入錯誤!@_@"); //則彈出驗證碼輸入錯誤 createCode();//刷新驗證碼 document.getElementById("input").value = "";//清空文本框 } else { //輸入正確時 alert("^-^"); //彈出^-^ } } </script> </body> </html>

servlet中的方法:

private void logincheck(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{// TODO 自動生成的方法存根req.setCharacterEncoding("utf-8");String a = req.getParameter("name");String b = req.getParameter("password");int k=service.logincheck(a,b);if(k==0) {req.setAttribute("message", "用戶名或密碼錯誤!");req.getRequestDispatcher("login.jsp").forward(req,resp);}else if(k==2){req.setAttribute("message", "登錄成功");req.getRequestDispatcher("index.jsp").forward(req,resp);}}

?service中的方法:

public int logincheck(String a,String b) {int f=0;if(dao.logincheck(a,b)) f=2;return f;}

dao層方法:

public boolean logincheck(String x, String y) {// 登錄驗證boolean f=false;String sql = "select * from account where name='" + x + "'and password='" + y + "'";Connection conn = Shujuku.conn();Statement state = null;ResultSet rs = null;try {state = conn.createStatement();rs = state.executeQuery(sql);while(rs.next()) {f = true;}} catch (Exception e) {e.printStackTrace();} finally {Shujuku.close(state, conn);}return f;}

?

轉載于:https://www.cnblogs.com/sengzhao666/p/10457157.html

總結

以上是生活随笔為你收集整理的密码登录源码(jsp+java+数据库)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。