最近在使用swfupload多文件上传插件,但是一直不成功,不知道错在哪里,项目是SSH框架,swfupload的位置如图:前台JSP中的JS代码如下:
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
upload_url: "swfupload/FileUploadServlet",
// File Upload Settings
file_size_limit : "50 MB", // 1000MB
file_types : "*.*",//设置可上传的类型
file_types_description : "所有文件",
file_upload_limit : "10",

file_queue_error_handler : fileQueueError,//选择文件后出错
file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
file_queued_handler : fileQueued,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,

// Button Settings
button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: 100,
button_height: 18,
button_text : '<span class="button">添加附件</span>',
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
button_text_top_padding: 0,
button_text_left_padding: 18,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,

// Flash Settings
flash_url : "swfupload/swfupload.swf",

custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: true  //是否显示调试窗口
});
};
function startUploadFile(){
swfu.startUpload();
} </script>body中代码如下:
<span id="spanButtonPlaceholder"></span>
   <div id="divFileProgressContainer" style="width:200;display:none;"></div>
<div id="thumbnails">
<table id="infoTable" border="0" width="50%" style="border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;margin-top:8px;">
</table>
</div>web.xml代码如下:
 <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>FileUploadServlet</servlet-name>
    <servlet-class>com.bbez.servlet.FileUploadServlet</servlet-class>
    <init-param>
<param-name>fileSizeLimit</param-name>
<param-value>50</param-value>
</init-param>
  </servlet>
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>DeleteFileServlet</servlet-name>
    <servlet-class>com.bbez.servlet.DeleteFileServlet</servlet-class>
  </servlet><servlet-mapping>
    <servlet-name>FileUploadServlet</servlet-name>
    <url-pattern>/admin/swfupload/FileUploadServlet</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>DeleteFileServlet</servlet-name>
    <url-pattern>/DeleteFileServlet</url-pattern>
  </servlet-mapping>运行结果显示:,看似图片上传成功,但是实际上并没有上传到服务,调试代码显示异常出现在:FileUploadServlet.java中的multi = new MultipartRequest(request, saveDirectory, maxPostSize, encoding, rename);
控制台错误为:
java.io.IOException: Corrupt form data: premature ending
at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:207)
at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:223)
at com.bbez.servlet.FileUploadServlet.doPost(FileUploadServlet.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619),请问到底是哪里出问题了呢??(以上是在FF中的结果)在IE6中会报另一个异常:
SWF DEBUG: 
Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.*
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象我测了下,异常从这里抛出:
function fileDialogComplete(numFilesSelected, numFilesQueued) {
try {
if (numFilesQueued > 0) {
document.getElementById('btnCancel').disabled = "";
this.startUpload();
}
} catch (ex) {
this.debug(ex);
}
}到底是什么问题呢?我几乎是完全用的别人的可运行的代码,只是位置变了一些,为什么我的就运行不成功呢?没分了,大家帮帮忙,感激不尽!!!

解决方案 »

  1.   

    /*重写文件上传完毕的方法*/

       function uploadComplete(file) {
    try {

    /*  I want the next upload to continue automatically so I'll call startUpload here */
    if (this.getStats().files_queued == 0) {
    document.getElementById(this.customSettings.cancelButtonId).disabled = true;
    //document.getElementById("nowDate").value=this.settings.post_params["uploadBatch"];


    } else {
    this.startUpload();
    }
    //getUploadFile(file);//这个是我自己的方法,不用管
    } catch (ex) {
    this.debug(ex);
    }
    }试试这个行不行,我自己改的