当前位置: 代码迷 >> J2EE >> struts2上传文件,如何获取文件的后缀名
  详细解决方案

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

热度:88   发布时间:2016-04-22 02:24:23.0
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
  相关解决方案