Struts2上传图片问题
我把图片上传到本地项目子目录文件夹下面,在eclipse中 每次要刷新文件夹才可以出来,现在把项目放到服务器上面,每次上传后,只是把文件路径保存到了数据库,而项目目录下面的文件夹,并没有上传的图片,该怎么办,
public class UploadFile {
private static final int BUFFER_SIZE = 16 * 1024;
String imageFileName;
public static InputStream in;
public static OutputStream out;
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public static int getBufferSize() {
return BUFFER_SIZE;
}
private static void copy(File src, File dst) {
try {
try {
in = new BufferedInputStream(new FileInputStream(src),
BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst),
BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0) {
out.write(buffer);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getExtention(String fileName) {
int pos = fileName.lastIndexOf(".");
return fileName.substring(pos);
}
public String saveImage(File myFile) {
imageFileName = new Date().getTime() + getExtention(fileName);
// File imageFile = new
// File(ServletActionContext.getServletContext().getRealPath("/uploadImage")
// + "/" + imageFileName);
File imageFile = new File("D:/java/workspaces/mjms/WebRoot/image" + "/"
+ imageFileName);
copy(myFile, imageFile);
return imageFileName;
}
}
扫码下载作业帮
拍照答疑一拍即得