日期:2014-05-20  浏览次数:20680 次

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