【问题标题】:How to get the param which content-type is x-www-form-urlencoded in Struts 2如何在 Struts 2 中获取内容类型为 x-www-form-urlencoded 的参数
【发布时间】:2016-12-30 02:32:07
【问题描述】:

请求是这样的:

在服务器中,我有一个这样的 bean:

@Data
public class TechInfo {
    private int shopID;    
    private String name;   
    private int experience;   
    TechnicianTitleInfo technicianTitleInfo;  
    private String skill;
}

如何在 Struts2 中获取请求参数?

我在操作中声明了一个 TechInfo,但在 Struts2 解析后它的值为 null。

动作是这样的:

public class AjaxAction{

    @Getter @Setter private TechInfo techInfo;

    protected void jsonExecute() throws Exception {
      //need the techInfo
    }
}

【问题讨论】:

  • jsonExecute()是哪个方法,在哪里调用(显然不是动作方法,因为它是void)?您能否显示用于此调用的拦截器堆栈,以及可能包含参数的 JSP sn-p 吗?
  • @yonney.yang 您使用错误的参数名称来填充操作属性,要么更改名称,要么手动检索参数。

标签: java struts2 parameter-passing httprequest getter-setter


【解决方案1】:

正确的参数格式是使用Dot Notation

techInfo.picID
techInfo.name
techInfo.technicianTitleInfo.titleId

等等。

【讨论】:

    【解决方案2】:

    如何获取内容类型为 x-www-form-urlencoded 的参数

    Struts2 正在使用request.getParameterMap()

    我在操作中声明了一个 TechInfo,但在 Struts2 解析后它的值为 null。

    该值为null,因为TechInfo 未绑定到操作类变量。请求参数名与变量名techInfo一致。

    【讨论】:

      猜你喜欢
      • 2015-04-02
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2020-04-21
      • 2021-01-21
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多