先上代码:
这是login.jsp中的部分:
<jsp:useBean id="Link" scope="page" class="dcl.util.login.LoginBean" /> 
    <% 
        String inputID =request.getParameter("id"); 
        String inputPwd =request.getParameter("password");  
        boolean flag;
       
        if (inputID != null && inputPwd != null) { 
           flag = Link.logon(inputID, inputPwd);
           if (flag){ 
              response.sendRedirect("usermain.jsp"); 
          }else{ 
              response.sendRedirect("register.jsp");            
          }             
       } 
    %>
这是LoginBean.class中的部分:
package dcl.util.login;
import java.sql.*;public class LoginBean {
private Connection conn = null;
private Statement stmt = null;
private ResultSet rs = null;
private boolean flag;

public boolean logon( String inputID, String inputPwd ) 
throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException 
{
       try{
new com.mysql.jdbc.Driver();
Class.forName("com.mysql.jdbc.Driver").newInstance();

         conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/dcl_2_tc_db?characterEncoding=UTF-8", 
         "root", 
         "1991727");

stmt = conn.createStatement();
rs = stmt.executeQuery("select * from user-puerpera-password");

flag = false;
while(rs.next()){
      String id = rs.getString("ID");
      String password = rs.getString("password");
      if( id.equals(inputID) && password.equals(inputPwd) ){
      flag = true;
      break;
      }
         }
     }catch(SQLException e){
e.printStackTrace();
}

if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();

return flag;
}
}
目的:
用户输入用户名和密码后,用logon(id, pwd)在数据库里查找有无该用户,根据返回值判断打开的页面。
问题:
发现返回值一直是false。
数据库名称是dcl_2_tc_db,表名为user-puerpera-password,有两列,一列是ID,类型是varchar;一列是password,类型是varchar,使用的字符集是utf-8,网页使用的字符集也是utf-8,都使用gbk时也试过,返回的依然是false。
感觉是rs = stmt.executeQuery("select * from user-puerpera-password");这句有问题,还没学数据库呢。
请大家帮帮忙吧,一上午就搞了这么一点,郁闷死了。