xxzmr1314
xxzmr1314
2017-06-02 08:30
采纳率: 44.4%
浏览 3.5k
已采纳

java web写的jsp登陆页面中如何匹配数据库

就是一个jsp登陆页面中,输入用户名和密码,如何连接上数据库并且与数据库中储存的用户名和密码匹配,求助各位大神。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

11条回答 默认 最新

  • u013829202
    觅夜的黑 2017-06-02 08:42
    已采纳

    jsp的用户名或者密码,到servlet通过request.getparameter(" xx");获取,通过jdbc存到数据库中。 http://blog.csdn.net/u013829202/article/details/52461437

    点赞 评论
  • qq_18895659
    AngusC· 2017-06-02 08:27

    不就是写jdbc么,百度一大推。

    点赞 评论
  • yuehailin
    yuehailin 2017-06-02 08:30

    可以尝试通过jdbc连接数据库,并将用户输入的信息与用户的数据库信息进行比较。慕课有关于java的视频教程。

    点赞 评论
  • FiangAsDre
    GreenRookie 2017-06-02 08:32

    前端校验完成后,ajax发送后台,后台处理与数据库校验

    点赞 评论
  • wodewojueding
    wodewojueding 2017-06-02 08:46

    1、将jsp页面的用户名密码传到servlet
    2、链接数据库,根据用户名读取当前用户信息;(Java连接数据库读取数据,百度即可)
    3、比较传入的密码是否和读取到的用户密码相同;
    4、返回结果

    点赞 评论
  • void_1912

    直接贴代码吧,写的是有点low,不过还能用用

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" %>
    <%@ page import="java.sql.*"%> 
    <%!  
        public static final String DRIVER = "com.mysql.jdbc.Driver";  
        public static final String USER = "root";  
        public static final String PASS = "123456";  
        public static final String URL = "jdbc:mysql://localhost/biyesheji?characterEncoding=utf8";  
    %>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <style type="text/css">
        table.hovertable {
            font-family: verdana,arial,sans-serif;
            font-size:18px;
            color:#333333;
            border-width: 1px;
            border-color: #999999;
            border-collapse: collapse;
        }
        table.hovertable th {
            background-color:#c3dde0;
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }
        table.hovertable tr {
            background-color:#d4e3e5;
        }
        table.hovertable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }
        </style>
        <!-- PAGE TITLE -->
        <title>学生成绩查询</title>
        <%@ include file="style.jsp" %>
    
    </head>
    
    <body>
        <!-- ===================================
            PRELOADER
        ==================================== -->
        <div class="preloader">
            <div class="status"></div>
        </div>
    
        <!-- ===================================
            HEADER
        ==================================== -->
        <header>
            <!-- Navigation Menu start-->
            <nav class="navbar clean-main-menu" role="navigation">
                <div class="container">
    
                    <!-- Navbar Toggle -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
    
                        <!-- Logo -->
                        <a class="navbar-brand" href="index.html"><img style="width:200px" class="logo" id="logo" src="<%=request.getContextPath()%>/images/logo.jpg" alt="Page"></a>
    
                    </div>
                    <!-- Navbar Toggle End -->
    
                    <!-- navbar-collapse start-->
                    <div id="nav-menu" class="navbar-collapse collapse" role="navigation">
                        <ul class="nav navbar-nav clean-menu-wrapper">
                            <li>
                                <a href="<%=request.getContextPath()%>/student">个人中心</a>
                            </li>
                            <li>
                                <a href="<%=request.getContextPath()%>/student/chooseclass">选课管理</a>
                            </li>
                            <li class="active">
                                <a href="<%=request.getContextPath()%>/student/mark">成绩查询</a>
                            </li>
                            <li>
                                <a href="<%=request.getContextPath()%>/student/subject">班级课表</a>
                            </li>
                            <li>
                                <a href="<%=request.getContextPath()%>/student/teache">教师评价</a>
                            </li>      
                        </ul>
    
                    </div>
                    <%@ page import="java.io.*,java.util.*" %>
                    <% String username = (String)session.getAttribute("username");%>
                    <p style="float:right;"><a href="<%=request.getContextPath()%>/login">
                    <% 
                        if(username != null){
                            out.print("<a href=\"\">"+username+"</a>"+",<a href=\"/biyesheji/login/logout\">"+"注销</a>");
                        } else out.print("<a href=\"/biyesheji/login\">【登陆】</a>");
                    %></p>
                </div>
            </nav>
            <!-- Navigation Menu end-->
        </header>
    
        <!-- ===================================
            MAIN
        ==================================== -->
    
      <section id="contact" class="clean-section-wrapper clean-contact-section background-one" data-stellar-background-ratio="0.5">
            <div class="clean-parallax-overlay"></div>
            <div class="container">
                <div class="row">
    
                    <!-- Section Header -->
                    <div class="col-sm-8" style="margin-top: 50px;">
    
                        <table class="hovertable">
                            <tr>
                                <th>课程代号</th><th>课程名称</th><th>任课教师</th><th>成绩</th>
                            </tr>   
    <%  
        String user = null;  
        String pass = null;  
        try{  
            Class.forName(DRIVER);  
            Connection con = DriverManager.getConnection(URL,USER,PASS);  
            String sql = "SELECT * FROM mark WHERE username=\""+username+"\"";  
            PreparedStatement stat = con.prepareStatement(sql);  
            ResultSet rs = stat.executeQuery();    
    
            while(rs.next()){         
                String classnumber = rs.getString("classnumber");
                String classname = rs.getString("classname");
                String teachername = rs.getString("teachername");
                int mark = rs.getInt("mark");
                int id = rs.getInt("id");
    
                out.println("<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">");
                out.println("<td>"+classnumber+"</td><td>"+classname+"</td><td>"+teachername+"</td><td>"+mark+"</td>");
                out.println("</tr>");   
            } 
            con.close();
            }
            catch(Exception e){  
    
        }  
    %>                                      
                        </table>          
                    </div>
                </div>      
            </div>
    
    
    
        </section>
        <!-- ===================================
            FOOTER SECTION
        ==================================== -->
        <%@ include file="script.jsp" %>
    
    </body>
    </html>
    
    
    点赞 评论
  • xiaowei09124
    xiaowei09124 2017-06-02 09:13

    这个需要JDBC、Ajax技术。
    输入账号密码后触发JavaScript里的ajax方法,然后到Java后台调用程序,查出和账号匹配的账号、密码。
    若数据查不到和账号匹配,直接弹出账号错,
    若账号正确,密码不正确,则弹出密码错。

    点赞 评论
  • sun1021873926
    夕阳雨晴 2017-06-02 09:14
    点赞 评论
  • w2298119289j
    哆啦A梦丶幻想 2017-06-02 10:35

    写一个jdbc和数据库连接,在写dao方法进行账号密码判定最后根据返回的值(true|false)判断账号密码是否正确

    点赞 评论
  • ljheee
    ljheee 2017-06-04 03:54

    连接上数据库并且与数据库中储存的用户名和密码匹配,就是用Java的JDBC操作数据库

    点赞 评论
  • sinat_34727879
    顾初r 2017-06-04 04:12

    可以action到servlet里面连接数据库

    点赞 评论

相关推荐