首页 > 技术文章 > struts2表单数据无法自动注入

alcc 2014-04-07 11:48 原文

场景:

     在实现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     }

 

推荐阅读