如果提交表单信息到action处理,发现有错误,比如密码验证错误或者其他,则需要发一条信息给登录界面,说明原因。
在action中加代码:if(isLogin){
//保存学生记录到session范围
TbStudent student = studentService.getStudentByID(this.id);
Map session = ActionContext.getContext().getSession();
session.put("studentInfo", student);
return "studentSuccess";
}else{
addActionError("该学生编号不存在,或者密码不正确!");
return INPUT;
}
- boolean islogin = ****//验证登录是否成功
- if(isLogin){
- //保存学生记录到session范围
- TbStudent student = studentService.getStudentByID(this.id);
- Map session = ActionContext.getContext().getSession();
- session.put("studentInfo", student);
- return "studentSuccess";
- }else{
- addActionError("该学生编号不存在,或者密码不正确!"); //添加actionerror
- return INPUT;
- }
在登录的jsp页面中,
- <tr>
- <td colspan="2"><FONT color="red"><s:actionerror/></FONT></td><!--显示错误信息 -->
- </tr>
如果登录校验错误,就会显示addActionError里的信息。