struts2表单数据无法自动注入
场景:
在实现struts2的注解方式的拦截器后,发现前台form submit到后台的数据无法被action中的类接收。
原因:
action默认的拦截器是defaultStack,当我们实现自己拦截器后会覆盖原来的拦截器。
解决:
加上默认的拦截器
1 @Action(value = "/loginin", results = { 2 @Result(name = SUCCESS, location = "public/home.jsp", type = "dispatcher"), 3 @Result(name = "login", location = "public/login.jsp", type = "dispatcher"), 4 @Result(name = "loginError", location = "public/loginError.jsp", type = "dispatcher") }, interceptorRefs = { 5 @InterceptorRef("timer"),@InterceptorRef("auth"),@InterceptorRef("defaultStack") }) 6 public String loginin() { 7 logger.info(JSON.toJSON(user)); 8 boolean status = userService.logininVerify(user); 9 if (status == true) { 10 session.put("ROLE", role); 11 return SUCCESS; 12 } else { 13 return "loginError"; 14 } 15 }
任凭弱水三千,我只取一瓢饮