首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

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

2012-02-27 
struts2上传文件,怎么获取文件的后缀名jsp代码HTML codeinput namecmpPic class{validate:{required

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

热点排行