jsp代码
- HTML code
<input name="cmpPic" class="{validate:{required:true,accept:'bmp?|jpg|gif|png'}}" type="file"/>
java代码
- Java code
String path=ServletActionContext.getServletContext().getRealPath("/company_image"); File cmpPicSrc= new File(company.getCmpPic()); String newFileName=company.getCmpId()+"_"+System.currentTimeMillis()+".jpg"; File cmpPicDest= new File(path,newFileName); FileUtils.copyFile(cmpPicSrc, cmpPicDest);
为什么cmpPicSrc的后最是tmp啊,我上传的是个png 文件啊
------解决方案--------------------
在客户端用js截取
服务器端直接substring