读书人

struts2上传文件如何获取文件的后缀

发布时间: 2012-02-27 10:00:22 作者: rapoo

struts2上传文件,怎么获取文件的后缀名
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

读书人网 >J2EE开发

热点推荐