jsp代码
  <input name="cmpPic" class="{validate:{required:true,accept:'bmp?|jpg|gif|png'}}" type="file"/>java代码                 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 文件啊

解决方案 »

  1.   

     private static String getExtention(String fileName)  {   
                int pos = fileName.lastIndexOf( "." );   
            return fileName.substring(pos);   
       } 
    直接截取就可以了
      

  2.   

     private static String getExtention(String fileName)  {   
                int pos = fileName.lastIndexOf( "." );   
            return fileName.substring(pos);   
       } 
    直接截取就可以了
      

  3.   

     private static String getExtention(String fileName)  {   
                int pos = fileName.lastIndexOf( "." );   
            return fileName.substring(pos);   
       } 
    直接截取就可以了
      

  4.   

    这样子可以:<input type="file"  maxlength="5" accept="gif|jpg|doc|docx|xls|txt" />
      

  5.   

    把accept属性里的后缀名换成你需要的就可以了。
      

  6.   

    struts2 上传文件在action国必须提供
            private File url;  
    private String urlContentType; // 上传文件类型
    private String urlFileName; // 上传文件的真实名字
    三个属性,且action必须实现一个ServletResponseAware
    String fileEx = urlFileName.substring(urlFileName.indexOf("."),
    urlFileName.length());
    可以获取文件后缀
      

  7.   

    在客户端用js截取
    服务器端直接substring
      

  8.   

    private static String getExtention(String fileName) {   
      int pos = fileName.lastIndexOf( "." );   
    return fileName.substring(pos);   
    }  
    直接截取就可以了
      

  9.   


    哥 我不用 struts 的<s:file>标签 fileName哪里来?,
      

  10.   


    但是在action中获取还是用这个  哈哈  支持