Загрузка файла Struts 2 - исключение нулевого указателя
Я пытаюсь загрузить файл с помощью Struts2 в сочетании с Spring. Но, как-то после достижения моего класса действий, мой файл,filename
и тип содержимого файла все выходят какnull
, Я пытался найти проблему, но безрезультатно. Ниже приведен код для загрузки моего файла:
index.jsp
Struts.xml
10240
text/plain
displayResultsJSP
ApplicationContext-web.xml
ManagePlanUploadAction
package com.hix.action.planmgmt;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class ManagePlanUploadAction extends ActionSupport{
private HttpServletRequest request;
private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
public void setServletRequest(HttpServletRequest paramHttpServletRequest) {
this.request = paramHttpServletRequest;
}
public HttpServletRequest getServletRequest() {
return request;
}
public File getFileUpload() {
return fileUpload;
}
public void setFileUpload(File fileUpload) {
this.fileUpload = fileUpload;
}
public String getFileUploadContentType() {
return fileUploadContentType;
}
public void setFileUploadContentType(String fileUploadContentType) {
this.fileUploadContentType = fileUploadContentType;
}
public String getFileUploadFileName() {
return fileUploadFileName;
}
public void setFileUploadFileName(String fileUploadFileName) {
this.fileUploadFileName = fileUploadFileName;
}
public String executeFileUploadDemo() throws Exception {
try {
String filePath = "C:/Myuploads2";
System.out.println("Server path:" + filePath);
File fileToCreate = new File(filePath, fileUploadFileName);
FileUtils.copyFile(fileUpload, fileToCreate);
} catch(Exception e) {
e.printStackTrace();
addActionError(e.getMessage());
return SUCCESS;
}
System.out.println("File :" + fileUpload);
System.out.println("Filename : " + fileUploadFileName);
System.out.println("File type : " + fileUploadContentType);
return SUCCESS;
}
}
плитка-def.xml
Result.jsp
File Name :
<br>
Content Type :
<br>
File :