Caused by: java.lang.NoSuchMethodException: xhy.shjc.UserAction.setUploadFile([Ljava.lang.String;)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230)
... 63 more
/-- Encapsulated exception ------------\
java.lang.NoSuchMethodException: xhy.shjc.UserAction.setUploadFile([Ljava.lang.String;)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478)
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:2315)
at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:77)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315)
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:217)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)
。。。。
Action的代码是
package xhy.shjc;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class UserAction{
//public User user;
private File uploadFile;
private String fileName;
public String add(){
try {
FileUtils.copyFile(uploadFile, new File("g:/Temp/"+fileName));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(fileName);
return "success";
}
public File getUploadFile() {
return uploadFile;
}
public void setUploadFile(File uploadFile) {
this.uploadFile = uploadFile;
}
public void setUploadFileFileName(String fName) {
fileName = fName;
}
public void setUploadFileContentType(String ct){
System.out.println(ct);
}
struts.xml:
<action name="test" class="xhy.shjc.UserAction">
<!-- <interceptor-ref name="defaultStack"></interceptor-ref> -->
<result name="success">
/success.jsp
</result>
</action>
jsp:
<form action="test" method="post" enctype="multipart/formdata">
<input type="hidden" name="method:add">
<input type="file" name="uploadFile">
<input type="submit" name="submit" value="上传文件">
<s:debug></s:debug>
</form>
------最佳解决方案--------------------------------------------------------
enctype="multipart/formdata"错了应该是enctype="multipart/form-data