Html網頁鏈接數據庫驗證賬戶密碼(新手)



連接代碼(其中用到了連接池,不要忘記Jar包、拉入配置文件和工具類):


 

 1 package cn.Wuchuang.Servlet;
 2 
 3 import org.springframework.jdbc.core.JdbcTemplate;
 4 
 5 import javax.servlet.ServletException;
 6 import javax.servlet.annotation.WebServlet;
 7 import javax.servlet.http.HttpServlet;
 8 import javax.servlet.http.HttpServletRequest;
 9 import javax.servlet.http.HttpServletResponse;
10 import java.io.IOException;
11
12

@WebServlet("/ServletDrZuanJie")

13 public class ServletDrZuanJie extends HttpServlet {

14     JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

15     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
16         System.out.println("提交方式為Post");
17         String username = request.getParameter("username");
18         String password = request.getParameter("password");
19         System.out.println("賬號為"+username+"密碼為"+password);

20         String sql = "select count(*) from zh where uname='"+username+"' and upd = '"+password+"'"; 21         Long aLong = jdbcTemplate.queryForObject(sql, Long.class); 22  System.out.println(aLong); 23         if (aLong!=0){ 24             System.out.println("登陸成功"); 25         }else { 26             System.out.println("登錄失敗"); 27  }

28     }
29 
30     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31         this.doPost(request,response);
32     }
33 }

網頁代碼(在form標簽中加入鏈接類的名稱和鏈接方式,於上面的保持一致):


 

  1 <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4     <meta charset="UTF-8">
  5     <title>Title</title>
  6     <link rel="stylesheet" type="text/css" href="css/DluWl.css"/>
  7 </head>
  8 <body>
  9 <form action="/ServletDrZuanJie" method="post">
 10 <!--總布局-->
 11 <div id="box">
 12     <!--
 13         作者:offline
 14         時間:2019-04-09
 15         描述:logo布局
 16     -->
 17     <div id="logo">
 18 
 19         <div class="logo1">
 20             <img src="img/logo.png" id="img1"/>
 21             <span style="font-weight:100;color: #A09AA1;" id="w2">求婚鑽戒領導品牌</span>
 22         </div>
 23 
 24         <div class="logo1">
 25 
 26             <div class="tu1">
 27                 <img src="img/tips.png" id="img2">
 28             </div>
 29             <span style="font-weight: 100; color: #A09AA1;" id="w1">國際權威認證</span>
 30             <div class="tu2">
 31                 <img src="img/tips.png" id="img3">
 32             </div>
 33             <span style="font:'maiandra gd'; font-weight: 100; color: #A09AA1; "id="w3">十五年無理由退換</span>
 34 
 35             <div class="tu3">
 36                 <img src="img/tips.png" id="img4">
 37             </div>
 38             <span style="font:'maiandra gd'; font-weight: 100; color: #A09AA1; "id="w4">終身保養</span>
 39 
 40         </div>
 41 
 42     </div>
 43     <!--
 44         作者:offline
 45         時間:2019-04-09
 46         描述:主界面圖片
 47     -->
 48     <div id="bodys">
 49         <!--
 50             作者:offline
 51             時間:2019-04-09
 52             描述:北京圖
 53         -->
 54         <div class="ztu1">
 55             <!--
 56                 作者:offline
 57                 時間:2019-04-09
 58                 描述:登陸輸入框
 59             -->
 60             <div class="kj">
 61 
 62                     <hr id="r1" style="font-weight: 400;color: #1D1D1D;"/>
 63                     <h3 style="font-weight: 300;">歡迎登陸</h3>
 64                     <hr id="r2" style="font-weight: 400;color: #1D1D1D;" />
 65 
 66                     <input type="text" name="username" placeholder="請您輸入郵箱/手機號" class="sr">
 67                     <div class="imgs">
 68                         <img src="img/mb.png" class="imgs2"/>
 69                     </div>
 70 
 71                     <input type="password" name="password" placeholder="請輸入密碼" class="sr2"/>
 72                     <div class="imgss">
 73                         <img src="img/mb.png"class="imgs3"/>
 74                     </div>
 75                     <br />
 76                     <div class="jz">
 77                         <input type="checkbox" placeholder="10px">記住密碼
 78 
 79                     </div>
 80                     <a href="https://www.baidu.com" style="color: #3E4B53;text-decoration: none;" class="jz1">忘記密碼</a>
 81 
 82                     <input type="button" value="注冊" class="jz2"/>
 83                     <input type="submit" value="登陸" class="jz3"/>
 84                     <hr style="background-color: #EAEAEB; width: 400px;margin-top: 40px; " />
 85                     <div class="san">
 86                         <b style="font-weight: 300;font-size: 15px;margin-left: 35px;color: #D6B870;">更多合作網站賬戶請登錄:</b>
 87                         <img src="img/QQ.jpg" style="margin-left: 25px;"/>
 88                         <img src="img/wb.jpg" style="margin-left: 25px;"/>
 89                         <img src="img/wx.jpg" style="margin-left: 25px;"/>
 90                     </div>
 91 
 92             </div>
 93         </div>
 94     </div>
 95     <!--
 96         作者:offline
 97         時間:2019-04-09
 98         描述:尾部
 99     -->
100     <div id="tail" style="height: 500px;margin: 0 auto;text-align: center;color: #ABABAB;font-weight: 200;">
101         <b >
102             CapyriGht@ 2006-2015 www.DarryRing.com     戴瑞珠寶    All Rights Reserved. 粵ICP備100215號
103         </b><br /><br />
104         <b>
105             中國互聯網違法信息舉報重心 | 中國公安網絡110報警服務 | 本網站提供所售商品的正式發票
106         </b>
107     </div>
108 </div>
109 </form>
110 </body>
111 </html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM