//接收到的图片
private File wangEditorH5File;
/**
* 上传图片
*/
public void uploadfile() throws Exception{
String directory = request.getSession().getServletContext().getRealPath("/static/userImages/");
/**
* 文件路径不存在则需要创建文件路径
*/
File filePath = new File(directory);
if (!filePath.exists()) {
filePath.mkdirs();
}
String time=String.valueOf(System.currentTimeMillis());
String filename=time.substring(time.length()-5,time.length())+new Random().nextInt(1000)+".jpg";
File target=new File(directory,filename);
FileUtils.copyFile(wangEditorH5File, target);
String imgUrl = "http://localhost:8080/static/userImages/" + filename;
System.out.println(imgUrl);
ResponseUtil.write(response, imgUrl);
}
public void setWangEditorH5File(File wangEditorH5File) {
this.wangEditorH5File = wangEditorH5File;
}
wangEditor使用Struts2上传图片
最新推荐文章于 2024-01-19 22:16:25 发布