我想验证数据库中数据存储的用户名和密码。我在开发中使用Netbeans IDE。我遇到的问题是它保持显示一个错误页面,内容为内部服务器错误。有人能帮我检查我的代码吗?我有一些像这样的代码:jsp用数据库用户登录验证
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 = "[email protected]";
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与用户(用户名=爱丽丝,密码=爱丽丝)
只从代码中很难弄清楚你正在运行什么。如果你得到一个错误页面,可能是由于抛出了一些异常。也许你可以用你的stacktrace扩展这个帖子? – Jeroen