• 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;  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>
  • 相关阅读:
    bzoj1336: [Balkan2002]Alien最小圆覆盖
    bzoj3564: [SHOI2014]信号增幅仪
    [HDU5353]
    [codeforce1072D]
    [dp001]逛公园
    树上问题泛做
    [BZOJ2599]race
    [CEOI2019]MAGIC TREE
    [BZOJ2836]魔法树
    QTREE3
  • 原文地址:https://www.cnblogs.com/lxr521/p/10681259.html
Copyright © 2020-2023  润新知