首先要定义一个显示验证信息的类
如:
1 public interface ReturnObject { 2 3 public boolean isSuccess(); 4 5 public String getReason(); 6 7 } 8 9 public class DefaultReturn implements ReturnObject { 10 private boolean success; 11 private String reason; 12 13 public DefaultReturn(boolean success, String reason) { 14 this.success = success; 15 this.reason = reason; 16 } 17 18 @Override 19 public boolean isSuccess() { 20 return success; 21 } 22 23 @Override 24 public String getReason() { 25 return reason; 26 } 27 }
之后,返回类型就是这个类(返回到前台)。
前台的代码对信息进行验证
如(ajax的success函数):
success : function(dataObj) { if (true == dataObj["success"]) { location.href = ""; } else { alert(dataObj["reason"]); } }
时间: 2024-09-29 02:59:39