id: inputtext
name: inputtext要一个bean在bean中验证输入的id号和密码与数据库中的表login中的id和密码是否相符。如果符合返回yes 否则返回no刚学java,多指教

解决方案 »

  1.   

    select password 
    from user
    where id = ?;取到password后和输入的password比一下不就可以了吗
    String flag = "0";
    if("password(DB)".equals("password(画面)"){
        flag = "1"
    }
    flag为0时不存在该用户,为1时存在。
    其他的事情就是从数据库取值拉。
      

  2.   

    上面那个你还要判断,DB的password是不是空,要不会出现异常
      

  3.   

    function boolean checkpwd(id string, pwd String){boolean result = false;//驱动程序名
    String driverName="com.mysql.jdbc.Driver";
    //数据库用户名
    String userName="cl41";
    //密码
    String userPasswd="123456";
    //数据库名
    String dbName="db";//联结字符串
    String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection connection=DriverManager.getConnection(url);
    Statement statement = connection.createStatement();String sql="SELECT userid, password FROM login where userid="+id;
    ResultSet rs = statement.executeQuery(sql);
    if (rs.next()) {
      if (out.print(rs.getString(1) = pwd ) result = true;
    }
    }
      

  4.   

    忘记说了,我用的是jsf,登录窗口用的是<h:inputext>组件并绑定在bean上,请问该怎样提取验证。
      

  5.   

    一般password会不可逆加密啊.好像不沾边~~~