POST一个字符串数组从速度到struts ActionForm

时间:2013-02-11 15:06:16

标签: java struts velocity

我试图从struts Action Form中的速度模板中检索一个String数组:我的Html代码:

 <input type="checkbox" id="checkboxAFF01" value="AFF01" name="expert[1]"> 
 <input type="checkbox" id="checkboxAFF02" value="AFF02" name="expert[2]"> 
<input type="checkbox" id="checkboxAFF03" value="AFF03" name="expert[3]">

我的ActionForm:

private String[] expert;

 public String getExpert(int index) {
   return expertise[index];
 }

 public void setExpert(int index, String value) {
   expertise[index] = value;
 }

但是我收到了这个错误:

 2013-02-11 14:53:10,284 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].[MainServlet] - "Servlet.service()" pour la servlet MainServlet  exception
java.lang.NullPointerException
 at .....setExpert(TestForm.java:115)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils.java:1435)
 at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1013)
 at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
 at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
 at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:798)
 at com.oroad.stxx.plugin.StxxTilesRequestProcessor.processPopulate(StxxTilesRequestProcessor.java:201)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:205)
 at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:149)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
 at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

1 个答案:

答案 0 :(得分:0)

删除索引的getter / setter,并替换为只获取并设置数组的方法。

那就是说,我建议改用列表。