ACTION中if语句不能识别

lianyangshiyan 2009-12-10 04:13:41
private String username;
private String password;
private String password1;
private String email;
private String problem;
private String answer;
private String gender;
private String company;
private String address;
private String ecode;
private String phone;
private String ephone;
private String wangzhan;

public String zhuce() throws Exception {

HttpSession session = ServletActionContext.getRequest().getSession();
System.out.println("password:"+password);
System.out.println("password1:"+password1);
System.out.println("ysername:"+username);
System.out.println("company:"+company);
System.out.println("phone:"+phone);

if(""==username){
session.setAttribute("message", "请输入用户名!");
return "register-false1";
}
Userinfo user=userDao.findUserinfoByName(username);
if(user!=null){
session.setAttribute("message", "用户已存在!");
return "register-false1";
}
if(""==password){
session.setAttribute("message", "请输入密码!");
}
if(!(password.equals(password1))){
session.setAttribute("message", "两次密码不一致,请重新输入!");
return "register-false1";
}
if(""==phone){
session.setAttribute("message", "电话不能为空!请重新输入!");
return "register-false1";
}
if(""==company){
session.setAttribute("message", "公司名称不能为空,请重新输入!");
return "register-false1";
}

info.setAddress(address);
info.setAnswer(answer);
info.setCompany(company);
info.setEcode(ecode);
info.setEmail(email);
info.setEphone(ephone);
info.setGender(gender);
info.setPassword(password);
info.setPhone(phone);
info.setPhone(phone);
info.setProblem(problem);
info.setUsername(username);
info.setWangzhan(wangzhan);

Userinfo info1=new Userinfo();
info1=info;
System.out.println("problem:"+info.getProblem());
userService.registerUserinfo(info1);
session.setAttribute("message", "注册成功!");
return "register-true1";

}
........
又get,set方法!!!除了password1!=password时候能识别,其实if语句,比如username为空的时候,就不能识别!!!~
...全文
126 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
a2068879 2009-12-11
  • 打赏
  • 举报
回复
用euqals
MashiMaro_001 2009-12-11
  • 打赏
  • 举报
回复
== 是比较地址,equal比较的是内容,这个区分下
武津乐 2009-12-10
  • 打赏
  • 举报
回复
先输出来到底要比较的东西 是什么类型,然后再确定怎么比较!
飘啊飘 2009-12-10
  • 打赏
  • 举报
回复
这里可以用.isEmpty()方法来测试
gao11811 2009-12-10
  • 打赏
  • 举报
回复
打屁股的错误
以前犯过一次,问老师,老师就踢了我的屁股,我就再也不犯这种错误了
sean1203 2009-12-10
  • 打赏
  • 举报
回复
这东西可以调试,一步一步来跟踪,不过这明显是==的误用
Kreocn 2009-12-10
  • 打赏
  • 举报
回复
数字或者null用 ==
其余的,,请用equal

而且最好反过来用,避免万恶的NullPointException

比如
if(null==password || "".equal(password)){
}
yangxiao_jiang 2009-12-10
  • 打赏
  • 举报
回复
字符串用==判断,都不会返回ture的,因为比较的是内存,euqals比较的才是内容。
yh344847977 2009-12-10
  • 打赏
  • 举报
回复
对于String类型的值做判断用equals int类型的用双等
hqsq_love 2009-12-10
  • 打赏
  • 举报
回复
用equals
if (username.equals("")){

}
一般这个时候才用==
if (i == 99){

}
lihao1129 2009-12-10
  • 打赏
  • 举报
回复
equals方法没有重写吧?

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧