Database 数据库用户的jsp登录身份验证

Database 数据库用户的jsp登录身份验证,database,jsp,authentication,login,Database,Jsp,Authentication,Login,我想验证数据存储在数据库中的用户和密码。我在减速中使用Netbeans IDE。我面临的问题是,它会显示一个包含内部服务器错误内容的错误页面。谁能帮我查一下密码吗。我有一些这样的代码: LoginForm.jsp: <%@page contentType="text/html" pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" c

我想验证数据存储在数据库中的用户和密码。我在减速中使用Netbeans IDE。我面临的问题是,它会显示一个包含内部服务器错误内容的错误页面。谁能帮我查一下密码吗。我有一些这样的代码:

LoginForm.jsp:

    <%@page contentType="text/html" pageEncoding="UTF-8"%> 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
        <title>Login Form</title> 
    </head> 
    <body bgcolor="#D8CEF6"> 
        <h1>Login Page</h1> 
        <fieldset>
           <center>
      <legend><h2>Sign in Details</h2> </legend>
        <form action="LoginCheck.jsp" method="post"> 

            <br/>Username:<input type="text" name="username"/> 
            <br/>Password:<input type="password" name="password"/> 
            <br/>
            <tr>
            <td>usertype</td>
            <td>
                <select name="usertype">
                    <option value="student">student</option>
                    <option value="faculty">faculty</option>
                </select>
            </td>
            </tr>
            <tr>
                <td>
            <br/><input type="submit" value="Submit" name="bt"/> 
                </td>
            </tr>
        </form> 
    </center> 
                </fieldset>
        </body> 
        </html>
LoginCheck.jsp:

<%@page import ="java.sql.*" %>
<%@page import ="java.io.IOException" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@page import="java.io.*"%>
    <html> 
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Login Check</title> 
        </head> 
        <body> 
            <%
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            String userType = request.getParameter("usertype");
            String dbURL = "jdbc:derby://localhost:1527/learningApp";
            String dbuser = "learningApp";
            String dbpassword = "p@ssw0rd";
            Connection theConnection = null;
            PreparedStatement theStatement = theConnection.prepareStatement("select * from USERNAME where username=? and password=?");
            try{
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            }catch(Exception ex){
            System.out.println("Class Not Found");
            }
            try{
            theConnection = DriverManager.getConnection(dbURL, dbuser, dbpassword);
            }catch(Exception ex){
            System.out.println("Connection Error");
            }
            try{
                theStatement.setString(1,request.getParameter("username"));
                theStatement.setString(2,request.getParameter("password"));
                ResultSet theResult = theStatement.executeQuery();
                if(theResult.next()){
            response.sendRedirect("Home.jsp");
        }

            }catch(Exception ex){
            System.out.println("Statement Error");
            }


            %>
    </body> 
    </html>
我的数据库名为learningApp,密码为p@ssw0rd
并且有一个名为USERNAME的表,其中USERNAME=alice,password=alice

您可能希望将derbyclient.jar和derby.jar放在WebContent/WEB-INF/Lib中,并将其包含在构建路径中

更新:

我将您的代码LoginCheck.jsp更改为,我使用的是Oracle DB。对我来说似乎很好

 <body> 
        <%
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String userType = request.getParameter("usertype");
        String driver = "oracle.jdbc.driver.OracleDriver";
        String dbURL = "jdbc:oracle:thin:@10.113.130.22:1521:ORCL";
        String dbuser = "user";
        String dbpassword = "password";
        Connection theConnection = null;
        PreparedStatement theStatement = null;


            try{  
                Class.forName(driver);
                theConnection=DriverManager.getConnection(dbURL,dbuser,dbpassword);  
                theStatement = theConnection.prepareStatement("select * from USERNAME where username=? and password=?");
                theStatement.setString(1,request.getParameter("username"));
                theStatement.setString(2,request.getParameter("password"));
                ResultSet theResult = theStatement.executeQuery();

                if(theResult.next())
                    System.out.println("Success");
                else
                    System.out.println("Failed");

                }catch(Exception e){
                    System.out.println("Exception occured! "+e.getMessage()+" "+e.getStackTrace());
                }  
        %>
</body>

仅从代码中很难看出您遇到了什么。如果您得到一个错误页面,可能是由于抛出了一些异常。也许你可以用stacktrace扩展帖子?