0
struts2에서 파일 업로드를 시도 할 때 내보기에 유효성 검사 오류가 발생합니다. "업로드"필드의 필드 값이 잘못되었습니다. 는 그리고 JBoss의 콘솔에서 내가 얻을 :struts2에서 파일을 업로드 할 수 없습니다. 잘못된 필드 값
10:37:56,140 WARN [OgnlValueStack] Error setting expression 'upload' with value '[Ljava.lang.String;@17c7b19'
ognl.MethodFailedException: Method "setUpload" failed for object [email protected] [java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([Ljava.lang.String;)]
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1289)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478)
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
...
...
Caused by: java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([Ljava.lang.String;)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230)
/-- Encapsulated exception ------------\
java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([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)
내 JSP :
<div class="v4DDfiltering">
<s:fielderror/>
<s:form id="saveNewBannerForm" name="saveNewBannerForm"
action="SaveNewBannerAction" theme="simple" method="POST" enctype="multipart/form-data">
...
<div class="OneFilteringRow">
<s:label for="upload" value="Plik:*" />
<s:file id="upload" name="upload"/>
</div>
...
<div class="OneFilteringRow">
<s:url id="saveNewBannerUrl" action="SaveNewBannerAction" />
<sj:a href="%{saveNewBannerUrl}" targets="messagesDiv"
formIds="saveNewBannerForm">
Save
</sj:a>
</div>
</s:form>
</div>
내 액션 클래스 SaveNewBannerAction.java
public class SaveNewBannerAction extends BaseAction {
private static final long serialVersionUID = 1L;
private static final Log LOG = LogFactory.getLog(SaveNewBannerAction.class);
private boolean validate = true;
private File upload;// The actual file
private String uploadContentType; // The content type of the file
private String uploadFileName; // The uploaded file name
private String fileCaption;// The caption of the file entered by user
...
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String getFileCaption() {
return fileCaption;
}
public void setFileCaption(String fileCaption) {
this.fileCaption = fileCaption;
}
@Override
public void validate() {
LOG.info("Enter: validate()");
LOG.info("VALIDATE FIELDS");
...
if(upload == null) {
addFieldError("upload",
"Proszę uzupełnić pole: plik.");
validate = false;
} else {
if(!uploadContentType.contains("image")) {
addFieldError("upload",
"Wprowadzono niepoprawny format pliku. Plik musi być obrazkiem.");
validate = false;
}
}
LOG.info("Exit: validate()");
}
나는 당신의 도움에 감사 할 것이다.