Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将字符串数组从velocity发布到struts ActionForm_Java_Struts_Velocity - Fatal编程技术网

Java 将字符串数组从velocity发布到struts ActionForm

Java 将字符串数组从velocity发布到struts ActionForm,java,struts,velocity,Java,Struts,Velocity,我试图从struts ActionForm中的velocity模板中检索字符串数组: private String[] expert; public String getExpert(int index) { return expertise[index]; } public void setExpert(int index, String value) { expertise[index] = value; } 我的Html代码: <input type="c

我试图从struts ActionForm中的velocity模板中检索字符串数组:

private String[] expert;

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

 public void setExpert(int index, String value) {
   expertise[index] = value;
 }
我的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]">
但我得到了这个错误:

 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)

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

也就是说,我建议改为使用列表。

好的,这对我很有用:public String[]getExpt(){return expert;}public void setExpert(String[]value){this.experties=value;}