上传图片存储服务器项目文件夹,Struts2上传图片问题我把图片上传到本地项目子目录文件夹下面,在eclipse中 每次要刷新文件夹才可以出来,现在把项目放到服务器上面,每次上传后,只是把文件路径保存...

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;

}

}

c9eaa1d181c3afefa04c0c8e039594e9.png

扫码下载作业帮

拍照答疑一拍即得

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值