2
1-6969875-2644-t.jpg
을 업로드하면 이미지가 /home/xrcwrn/jvm/apache-tomcat-6.0.14/domains/xyz.com/ROOT/img/1-6969875-2644-t.jpg
으로 올바르게 업로드됩니다.sturuts 2의 사진을 tomcat의 디렉토리 대신 public_html 디렉토리에 업로드하려면 어떻게해야합니까?
하지만 실제로이 이미지를 /home/xrcwrn/public_html/img
폴더에 업로드하고 싶습니다.
나는 스트럿츠 2에서이 코드를 사용하고 있습니다 :
public String execute() {
try {
ServletContext servletContext = ServletActionContext.getServletContext();
String path =servletContext.getRealPath("/img");
System.out.println("Server path:" + path);
String filePath = servletContext.getRealPath(path);
File uploadDir = new File(filePath);
String relPath = uploadDir.getAbsolutePath();
//if the folder does not exits, creating it
if (uploadDir.exists() == false) {
uploadDir.mkdirs();
}
File fileToCreate = new File(path, this.userImageFileName);
FileUtils.copyFile(this.userImage, fileToCreate);
String pt = path + "/" + getUserImageFileName();
System.out.println("image path is :" + pt);
setImagePath(pt);
} catch (Exception e) {
e.printStackTrace();
addActionError(e.getMessage());
return INPUT;
}
System.out.println(" **************inside image upload***********");
return SUCCESS;
}