直入正题

假设有一个action,MyAction

public class MyAction extend actionSupport{

  private List<myBean> listBeans;

  private Set<MyBean> setBeans;

  //...此处省略setter和getter方法

}

 

public class MyBean{

  private int id;

  //...此处省略setter和getter方法

}

 

页面form表单请求MyAction并给listBeans和setBeans赋值

<input type="text" name="listBeans.myBean.id" /> //此处能正常接受参数信息

<input type="text" name="setBeans.myBean.id" />//此处无法正常接收参数信息

当接收参数值的对象是set时 必须设置Conversion转换器

在MyAction.java同目录下配置MyAction-conversion.properties的文件

配置如下:

KeyProperty_setBeans = id
Element_setBeans = MyBean
CreateIfNull_setBeans = true

并且需要做以下处理:

1、在MyAction中初始化setBeans = new HashSet<MyBean>();

2、将<input type="text" name="setBeans.myBean.id" />更改为<input type="text" name="setBeans.makeNew[0].myBean.id" />

这样Struts2才能正常接受参数。

相关文章:

  • 2022-03-01
  • 2021-07-21
  • 2021-11-13
  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2021-08-02
  • 2021-07-27
猜你喜欢
  • 2021-05-07
  • 2021-05-15
  • 2022-02-23
  • 2021-10-04
  • 2022-01-15
  • 2021-09-21
  • 2021-08-03
相关资源
相似解决方案