NutzCN Logo
问答 为什么图片上传到服务器上只要改了jsp代码就会自动删除
发布于 2550天前 作者 qq_418196a2 1276 次浏览 复制 上一个帖子 下一个帖子
标签:

为什么图片上传到服务器上只要改了jsp代码就会自动删除

	@At("/uploadhead")
	@AdaptBy(type=UploadAdaptor.class,args="ioc:upload")//对应js的名称执行ioc
	public Object headImg(HttpSession session,@Param("fileupload") TempFile tmpFile,
			AdaptorErrorContext errCtx,
			HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException{
		int uid=(int) session.getAttribute("me");
		if(errCtx!=null){
			log.info(errCtx.getAdaptorErr());
			return false;
		}
		if(tmpFile==null||tmpFile.getFile().length()<1024){
			return false;
		}
		log.debug(tmpFile.getMeta().getFileLocalName());
		File file=tmpFile.getFile();
		
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");//随机生成图片名称编码
		String dest = webPath(uuid) + "." + Files.getSuffixName(file).toLowerCase();//原始图片编码
		String smallPath = webPath(uuid) + "_128x128." + Files.getSuffixName(file).toLowerCase();//现有图片编码
		try {
			Images.zoomScale(file, new File(smallPath), 128, 128, Color.BLACK);//得到图片大小
			file.renameTo(new File(dest));
		} catch (Throwable e) {
			log.info(e);
			res.sendRedirect("../userinfo/page?id=error");
			return "";
		}
		String s="/upload/images/" + uuid + "."+ Files.getSuffixName(file).toLowerCase();//图片的绝对路径
		new UserService().headImg(s, uid, dao);
		res.sendRedirect("../userinfo/page?id=me");
	/*	req.getRequestDispatcher("../userinfo/page?id=me").forward(req, res);*/
		return null;
	}
	
	public String webPath(String path) {
		return Mvcs.getServletContext().getRealPath("/upload/images/")  + path;
	}
}
8 回复

tomcat?maven?执行redeploy的时候干掉了?

我用的是tomcat

只要修改了代码图片就会自动被删除

图片放到webapps之外吧

重启tomcat不会被删除 如果是修改代码就会被删除

好的 谢谢 我试一试

要怎么把 图片放在webApps之外 我试了好几次都不行

@qq_418196a2 配置文件里面定义个路径,图片文件统统存那里去

添加回复
请先登陆
回到顶部