import java.io.*;
import javax.servlet.http.*;
import com.web.test.SqlHelper;
import java.sql.*;public class LoginCl extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) {
doPost(req, res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res) {
res.setCharacterEncoding("GBK");
String username = req.getParameter("username");
String passwd = req.getParameter("passwd");
String sql = "select top 1 * from users where username=?";
String[] paras = {username};
ResultSet rs = null;

try {
     PrintWriter pw = res.getWriter();
     SqlHelper sh = new SqlHelper();
     rs = sh.query(sql, paras);
     String password =null;
    
     if(rs.next()) {
     password = rs.getString(2);
    
     System.out.println("password="+ password);
     System.out.println("passwd="+ passwd);
     System.out.println("passwd.equals(password)= "+passwd.equals(password));
    
     if(password.equals(passwd)) {
     System.out.println("aaa");
     res.sendRedirect("welcome?username="+username+"");
     }else {
     System.out.println("bbb");
     res.sendRedirect("login");
     }
     }else {
     System.out.println("ccc");
     res.sendRedirect("login");
     }
    
    
}catch (Exception ex) {
ex.printStackTrace();
}
}
}
Tomcat:
数据库连接成功!
password=aa
passwd=aa
passwd.equals(password)= false
bbb
为什么equals()是false呢?谢谢大家了~~~