[email protected]
要个完整点的例子,好用的

解决方案 »

  1.   

    jspsmartupload实例就行我自己写了一个不是很理想
      

  2.   

    给你个简单的吧。没有任何逻辑的!<form name="Formupdate" id="Formupdate" action="upload.jsp" method="post" enctype="multipart/form-data">
      <td class="b23"><input type="File" name="importFile" size="30"></td>
    </form>         SmartUpload mySmartUpload = new SmartUpload();
            // Initialization
            mySmartUpload.initialize(pageContext);
            // Upload
            mySmartUpload.upload();
            if (mySmartUpload.getFiles().getCount() > 0) {
                // Retreive the current file
                com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
                // Save it only if this file exists
                if (!myFile.isMissing()) {
                    // if fold not existed, auto create it
                    java.io.File tempDir = new java.io.File("c:\\temp\\");
                    try {
                        if (!tempDir.exists())
                            tempDir.mkdirs();
                    }
                    catch (Exception e) {
                        return;
                    }
                    // sample with a physical path
                    fileName = "c:\\temp\\" + myFile.getFileName();
                    myFile.saveAs(fileName, mySmartUpload.SAVE_PHYSICAL);
                }
                else {
                    logString=messageResource.getString("SpbmImport.MustChooseFile");
                    flagerror=true;
                }
            }
            else {
                return;
            }catch (Exception e) {
                out.println(e.getMessage());
                e.printStackTrace();
                try {
                    con.rollback();
                }
                catch (Exception sqle) {
                }
            }
            finally {
                try {
                    con.close();
                }
                catch (Exception sqle) {
                }
            }