这个需要三个方面的准备
1,是要数据库,要有一个表存放登陆用户名和密码的信息
2,是要有jsp的登陆页面。要有个入口去调用java程序判断数据是否正确
3,是要写后台的java处理数据的代码了。首先要写servlet类,要写操作数据库的类,还有就是web.xml文件的配置。
这只是一个大体的思路,具体的代码处理也不复杂。lz要试一试才好。还有啊,servlet楼主能够懂多少啊,java 的对象思想也很重要的,单纯的代码是很容易得 ,但是真正能够懂这些代码的逻辑关系,对楼主的能力提高才是至关重要的。

解决方案 »

  1.   

    select count(*) from 用户表 where 用户名字段="用户名" and 密码字段="密码"
      

  2.   


    /**
     * 
     * @param userName
     * @param password
     * @return result if return<True>
     * @throws SQLException
     */
    public boolean login(String userName, String password) throws SQLException {
    boolean result = false;
    Connection connection = "-----"; //最近创建一个数据连接
        PreparedStatement pStmt = connection.prepareStatement("select * from user_table where userName = ? and password = ?");
        pStmt.setString(1, userName);
        pStmt.setString(1, password);
        ResultSet rs = pStmt.executeQuery();
        if(rs.next()) {
         return result = true;
        }
        return result;
    }
      

  3.   

    3楼的  如果我输入的密码值是这样会怎么样呢?
    a' or 'a'='a
      

  4.   

    public boolean yanzheng(String name,String password){
         if(name.equals("123") && password.equals("123"))
              return true;
         else
              return false;
    }
      

  5.   


    我不想把登陆的用户名+密码放进数据库行吗?放数据库中总感觉不太安全。我以前玩儿过DVBBS7网站的网站默认数据库的路径,导致众多网站的数据库被下载,里面就存的有管理员的用户名+密码。上海萌芽杂志社网站、刘亦菲的亦菲仙居网站.....(俺可没进他们的后台吆!~)。我想把它存放到一个key.dat文件中。再加上验证码,验证码后再加155条干扰线(网上有这方面的资料)。
    就是不知道怎么实现的?因为有了验证码,所以令我有点没了方向。期待高手指点!~
      

  6.   

            public boolean login(String userName, String password) throws SQLException {
            boolean result = false;
            Connection connection = "-----"; //最近创建一个数据连接
             PreparedStatement pStmt = connection.prepareStatement("select *from user_table where   
            userName = ? and password = ?");
            pStmt.setString(1, userName);
            pStmt.setString(1, password);
            ResultSet rs = pStmt.executeQuery();
            if(rs.next()) {
                return result = true;
            }
            return result;
        }