为什么图片上传到服务器上只要改了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;
}
}