嗨,从这段代码中我得到空指针异常,当我要读取uploadfilename时,我正在尝试解决这个问题,但是这个问题没有解决,任何人都可以帮助我......
public class ImportAction extends ActionSupport implements ServletRequestAware {
private static final long serialVersionUID = 1L;
private File uploadFile;
private String uploadfileFileName;
private String uploadfileContentType;
private HttpServletRequest servletRequest;
public String getUploadfileFileName() {
return uploadfileFileName;
}
public void setUploadfileFileName(String uploadfileFileName) {
this.uploadfileFileName = uploadfileFileName;
}
public String getUploadfileContentType() {
return uploadfileContentType;
}
public void setUploadfileContentType(String uploadfileContentType) {
this.uploadfileContentType = uploadfileContentType;
}
public File getUploadFile() {
return uploadFile;
}
public void setUploadFile(File uploadFile) {
this.uploadFile = uploadFile;
}
RegisterDAO dao = new RegisterDAO();
/**
*
* @return
* @throws
* Exception
*/
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
String filePath = servletRequest.getSession().getServletContext().getRealPath("/");
System.out.println("filepath" + filePath);
System.out.println("file" + getUploadFile());
System.out.println("filename" + getUploadfileFileName());
File fileToCreate = new File(filePath, this.uploadfileFileName);
try {
FileUtils.copyFile(this.uploadFile, fileToCreate);
} catch (IOException e) {
addActionError(e.getMessage());
}
return SUCCESS;
// Model m = new Model();
// String result = m.fileimport(uploadFile, uploadfileFileName);
// String result = m.fileimport();
// if (result.equals(SUCCESS)) {
// return SUCCESS;
// } else {
// addActionError(getText(result));
// return "failure";
// }
}
@Override
public void validate() {
System.out.println("inside validate of LA");
}
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest; //To change body of generated methods, choose Tools | Templates.
}