com.jspsmart.upload.File file=su.getFiles().getFile(0);
String name = prodID +"."+file.getFileExt();
file.saveAs("/upload/"+name);

解决方案 »

  1.   

    那你只有追加一个操作,就是用prodID重新改文件名三
      

  2.   

    SmartUpload su = new SmartUpload();
    mySmartUpload.initialize(pageContext);
    //文件上传
    mySmartUpload.upload();
    File myFile = mySmartUpload.getFiles().getFile(0);
    if (!myFile.isMissing()) {
    myFile.saveAs( "upload/"+ prodID ); 
    out.println("已上传文件 " + myFile.getFileName() + "<BR>");}
      

  3.   

    com.jspsmart.upload.File file=su.getFiles().getFile(0);
    String name = prodID +"."+file.getFileExt();
    file.saveAs("/upload/"+name);
      

  4.   

    给你段代码。 String picture = "", pic = "";
        com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();      // Initialization
          mySmartUpload.initialize(config,request,response);
        try {
          // Upload
          mySmartUpload.upload();
          String servPath = request.getSession(true).getServletContext().getRealPath(request.getServletPath());
          String path1 = servPath.substring(0,servPath.lastIndexOf(System.getProperty("file.separator")));
          String dirPath = path1.substring(0,path1.lastIndexOf(System.getProperty("file.separator")) + 1) + "pictures" + System.getProperty("file.separator");
          com.jspsmart.upload.Files files = mySmartUpload.getFiles();
          com.jspsmart.upload.File myFile = files.getFile(0);
          if (!myFile.isMissing()) {
            pic = id + "_1" + myFile.getFileName().substring(myFile.getFileName().indexOf("."));
            myFile.saveAs(dirPath + pic);
            picture += pic;
            for (int i = 1; i < files.getCount(); i++) {
              myFile = files.getFile(i);
              if (!myFile.isMissing()) {
                pic = id + "_" + (i + 1) + myFile.getFileName().substring(myFile.getFileName().indexOf("."));
                myFile.saveAs(dirPath + pic);
                picture += "," + pic;
              }
            }
          }
        } catch (Exception e){
          out.println("Unable to upload the file.<br>");
          out.println("Error : " + e.toString());
      

  5.   

    谢谢各位 已经解决
    现在进一步提问,如何限制只能上传JPG图片?
    或者将上传的图片转为JPG格式?
    有办法吗?
      

  6.   

    因为我的prodID是唯一的,所以应该不会出现重名的现象吧?
      

  7.   

    javascript 查文件名的后缀或找开源项目转文件格式!