System.out.println() 输出为空不会往下执行,且不报错
今天在用ssh做登录页面的时候发现输入错误的用户名和错误的密码时jsp页面不会接收到request传来的login_infos,经过调试后发现程序卡在System.out.println(emp.getEname())这句话上,代码如下
public String doLogin(){
Emp emp = (Emp)loginService.login(this.user.getLoginuser());
//System.out.println(emp.getEname());如果emp为空不会报错也不会往下执行
try {
System.out.println(emp.getEmpno());//如果用trycatch把异常抛出,则会继续往下执行
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(emp);
if (emp == null) {
getRequest().setAttribute("login_infos", "用户名不存在");
return "fail";
} else {
if (this.user.getLoginpass() == null
|| "".equals(this.user.getLoginpass())) {
getRequest().setAttribute("login_infos", "密码为空");
return "fail";
} else {
if (this.user.getLoginpass().equals(
String.valueOf(emp.getEmpno()))) {
getSession().setAttribute("emp", emp);
/*
* req.setAttribute("login_infos", "登陆成功");
*/return "success";
} else {
getRequest().setAttribute("login_infos", "密码错误");
return "fail";
}
}
}
}
控制台输出hibernate的查询语句,程序没报错也不会往下执行,
Hibernate:
select
this_.empno as empno1_1_,
this_.ename as ename1_1_,
this_.job as job1_1_,
this_.sal as sal1_1_,
this_.comm as comm1_1_,
this_.deptno as deptno1_1_,
dept2_.deptno as deptno0_0_,
dept2_.dname as dname0_0_,
dept2_.loc as loc0_0_
from
emp this_
left outer join
dept dept2_
on this_.deptno=dept2_.deptno
where
this_.ename=?
order by
this_.ename asc
解决办法就是将System.out.println(emp.getEname());注释掉或者抛出异常,程序就会继续往下执行