我正在使用Netbeans。我已经为数据表创建了用户名和密码。我的登录名和密码无法访问我的另一个jsp文件,因此无法解决问题。它向我显示HTTP状态404-找不到。问题是什么?

以下是我的logincheck.jsp代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page language="Java" import="java.sql.*" %>
<!DOCTYPE html>

<body>

<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String userType = request.getParameter("usertype");

String driver = "oracle.jdbc.driver.localDriver";
String dbURL = "jdbc:derby://localhost:1527/Parts ";

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 USERS");

    theStatement.setString(1,request.getParameter("username"));
    theStatement.setString(2,request.getParameter("password"));

    ResultSet theResult = theStatement.executeQuery();

     if(theResult.next())
         System.out.println("welcome.jsp");
     else
         System.out.println("Failed");
}
catch(Exception e) {
    System.out.println("Exception occured! "+e.getMessage()+" "+e.getStackTrace());
}
%>
</body>

最佳答案

我认为这可能是错误的...

  theStatement = theConnection.prepareStatement("select * from USERS");


应该是这样的..

 theStatement = theConnection.prepareStatement("select * from USERS where Username=? and Password=?)

theStatement.setString(1,username);
theStatement.setString(2,password);
..
..


让我知道这个是否奏效....

10-05 22:55