读书人

疯了.字符串的怪有关问题

发布时间: 2012-02-01 16:58:19 作者: rapoo

疯了..字符串的怪问题
.深秋小雨(7338367) 17:01:17
public String validate(String username,String password)
{
String result = null;
LoginDao loginDao = new LoginDao();
User user = loginDao.queryById(username);

if(user!=null)
{
String temp = user.getPassword();
System.out.println(temp);
if(temp.equals( "lwd "))
{
System.out.println( "success ");
result = "success ";
}
else
{
System.out.println( "wrong password ");
System.out.println( "L: "+password+ ",D: "+temp);
result = "fail ";
}
}
else
{
System.out.println( "user does not exist ");
result = "fail ";
}

return result;
}

.深秋小雨(7338367) 17:01:57
总是登录不成功并且输出wrong password

.深秋小雨(7338367) 17:03:10
if(temp.equals( "lwd "))改成if(temp.equals(password))也一样,因为数据库里对应的password就是lwd

System.out.println(temp)的结果是lwd啊
"lwd ".equals(temp)的结果居然是false
不可能有空格,因为用了trim方法还是一样的结果。

搞了一下午了,晕啊。

[解决办法]
L?123的1?

String temp = user.getPassword().toUpperCase();
System.out.println(temp);
if(temp.equals( "lwd ".toUpperCase()))
{
System.out.println( "success ");
result = "success ";

试试
[解决办法]
debug一下看看.
喝杯茶冷静一下,问题就解决了!呵
[解决办法]
temp得值应该用空格
你这样输出temp得值看看
System.out.println( "[ " + temp + "] ");
[解决办法]
是不是大小写问题或者1和l搞混了

读书人网 >Java Web开发

热点推荐