如果提交表单信息到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;
            }

Java代码  struts2: addActionError 和s:actionerror
  1.                     boolean islogin = ****//验证登录是否成功  
  2.                     if(isLogin){  
  3.     //保存学生记录到session范围  
  4.     TbStudent student = studentService.getStudentByID(this.id);  
  5.     Map session = ActionContext.getContext().getSession();  
  6.     session.put("studentInfo", student);  
  7.     return "studentSuccess";  
  8. }else{  
  9.     addActionError("该学生编号不存在,或者密码不正确!"); //添加actionerror  
  10.     return INPUT;  
  11. }  

 在登录的jsp页面中,

Js代码  struts2: addActionError 和s:actionerror
  1. <tr>  
  2.     <td colspan="2"><FONT color="red"><s:actionerror/></FONT></td><!--显示错误信息 -->  
  3. </tr>  

 如果登录校验错误,就会显示addActionError里的信息。

相关文章:

  • 2022-12-23
  • 2021-10-28
  • 2021-04-09
  • 2021-07-30
  • 2021-09-19
  • 2021-11-29
  • 2022-01-05
猜你喜欢
  • 2021-07-09
  • 2021-08-15
  • 2021-10-02
  • 2021-10-09
  • 2021-10-16
相关资源
相似解决方案