当前位置: 代码迷 >> Java Web开发 >> uploadify组合struts2的时候文件取值出错
  详细解决方案

uploadify组合struts2的时候文件取值出错

热度:10416   发布时间:2013-02-25 21:07:51.0
uploadify结合struts2的时候文件取值出错
debug的时候进了action,可是在setUpload方法之前就报错了,错误信息在下面,jsp里面:
<s:form action="/theme/themeManage!insertTheme.action" id="insertThemeForm" method="post" theme="simple" enctype="multipart/form-data">
<input type="file" id="upload" name="upload" />
</s:form>

js里面:
$(function() {

$("#upload").uploadify({
'swf' : '../js/uploadify/uploadify.swf',
'uploader' : '/nbtback/theme/ajaxTheme!insert.action',
'cancelImg' : '../js/uploadify/uploadify-cancel.png',
'folder' : 'uploads',
'queueID' : 'fileQueue',
'auto' : true,
'width' : 130,
'height' : 30,
'fileObjName' : 'upload',
'multi' : true,//这里是指定能否上传多个,我改下
'simUploadLimit' : 2,//一次可以选择多少个文件 
'buttonText' : '浏览',//按钮文字
method : 'post',
onUploadError : function(file, code, msg, errStr) {
alert(errStr);
},
onUploadSuccess : function() {

}
});


action里面用来取值的文件相关的三个参数:
private File upload;
private String uploadFileName;// 文件的名称含有后缀
private String uploadContentType;// 文件的类型
get、set方法省略

报的错误如下:Cannot create type class java.io.File from value Submit Query - [unknown location]
at com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:152)
at com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:146)
at com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue(XWorkConverter.java:334)
at com.opensymphony.xwork2.ognl.OgnlTypeConverterWrapper.convertValue(OgnlTypeConverterWrapper.java:39)
at ognl.OgnlRuntime.getConvertedType(OgnlRuntime.java:1067)
at ognl.OgnlRuntime.getConvertedTypes(OgnlRuntime.java:1084)
at ognl.OgnlRuntime.getConvertedMethodAndArgs(OgnlRuntime.java:1110)
at ognl.OgnlRuntime.getAppropriateMethod(OgnlRuntime.java:1196)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1210)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1481)
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2318)
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:77)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2318)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
  相关解决方案