后台Action中有String数组expPros:
在form表单中试图通过以下方式向action中expPros赋值时:
结果报错:[quote]org.springframework.beans.factory.BeanCreationException: Error creating bean with name '[Ljava.lang.String;': Could not resolve matching constructor[/quote]
如果写成:
就不会抛上面错误了,但三个input输入框的值不会被赋给expPros:[quote]01/15/2011 01:40:19.203 ERROR ParametersInterceptor,204 - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'expPros[]' on 'class com.sgai.itms.equipment.web.ItmsEquipDetailsAction: Error setting expression 'expPros[]' with value '[Ljava.lang.String;@2a519b'
[/quote]
具体原因:
struts2 OGNL实例化数组的问题.
[url]http://blog.csdn.net/fuliangliang/archive/2007/10/15/1826560.aspx[/url][quote]Struts doesn't support array creation due to an issue with size determination. Kinda what I though earlier. So, I've changed it over to use a List<Integer> and that works fine.
The docs are very misleading on this point. I'd be more than happy to clean up the type conversion doc and also create an collection handling doc to help folks out with this issue. Let me know if I can help out at all.[/quote]
据此得出,通过struts2的action(或直接使用request)的方式向后台传java 数组的正确方式是各个input的name都取成后台数组名即可(如这里的expPros),[color=red][size=medium][b]不可以加[][/b][/size][/color]:[quote][b]三个input的值可以被传给Action中的数组expPros;并且也可以通过[color=red]request.getParameterValues("expPros")[/color]的方式得到一个String数组[/b]
private String[] expPros;
///get set
在form表单中试图通过以下方式向action中expPros赋值时:
<input type="text" name="expPros[0]" value="extProp1_VALUE">
<input type="text" name="expPros[1]" value="extProp2_VALUE">
<input type="text" name="expPros[2]" value="extProp3_VALUE">
结果报错:[quote]org.springframework.beans.factory.BeanCreationException: Error creating bean with name '[Ljava.lang.String;': Could not resolve matching constructor[/quote]
如果写成:
<input type="text" name="expPros[]" value="extProp1_VALUE">
<input type="text" name="expPros[]" value="extProp2_VALUE">
<input type="text" name="expPros[]" value="extProp3_VALUE">
就不会抛上面错误了,但三个input输入框的值不会被赋给expPros:[quote]01/15/2011 01:40:19.203 ERROR ParametersInterceptor,204 - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'expPros[]' on 'class com.sgai.itms.equipment.web.ItmsEquipDetailsAction: Error setting expression 'expPros[]' with value '[Ljava.lang.String;@2a519b'
String[] arr = request.getParameterValues("expPros");
///arr为null
[/quote]
具体原因:
struts2 OGNL实例化数组的问题.
[url]http://blog.csdn.net/fuliangliang/archive/2007/10/15/1826560.aspx[/url][quote]Struts doesn't support array creation due to an issue with size determination. Kinda what I though earlier. So, I've changed it over to use a List<Integer> and that works fine.
The docs are very misleading on this point. I'd be more than happy to clean up the type conversion doc and also create an collection handling doc to help folks out with this issue. Let me know if I can help out at all.[/quote]
据此得出,通过struts2的action(或直接使用request)的方式向后台传java 数组的正确方式是各个input的name都取成后台数组名即可(如这里的expPros),[color=red][size=medium][b]不可以加[][/b][/size][/color]:[quote][b]三个input的值可以被传给Action中的数组expPros;并且也可以通过[color=red]request.getParameterValues("expPros")[/color]的方式得到一个String数组[/b]
<input type="text" name="expPros" value="extProp1_VALUE">
<input type="text" name="expPros" value="extProp2_VALUE">
<input type="text" name="expPros" value="extProp3_VALUE">
String[] arr = request.getParameterValues("expPros"); /// 同Action的属性expPros一样,arr也为"[extProp1_VALUE, extProp2_VALUE, extProp3_VALUE]"
[/quote]