我用uploadify控件上传文件,出现httpError404错误
jsp代码如下:
<p><input type="file" name="uploadify" id="uploadify" /></p>
<p><a href="javascript:$('#uploadify').uploadify('upload','*')">Upload Files</a></p>
$(function() {
$("#uploadify").uploadify({
debug : true,
height : 30,
swf : '${pageContext.request.contextPath }/uploadify/uploadify.swf',
cancelImage : '${pageContext.request.contextPath }/uploadify/uploadify-cancel.png',
uploader : '<%=path%>/info/SysClientAction_upload.do',
width : 120,
auto: false,
buttonText : '选择文件',
method:'get',
fileObjName:'uploadify',//和input的name值一样,struts2就能接收处理
fileSizeLimit : '200KB',
uploadLimit:5,
multi: true,//设置同时上传多个文件
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString +","+errorCode+","+errorMsg);
}
});
});
我在struts中将文件存到服务器制定的文件中,结果是文件已经上传到服务器中了,可是还是报404错误。用debug调试,如下显示:
---SWFUpload Instance Info---
Version: 2.2.0 2009-03-25
Movie Name: SWFUpload_0
Settings:
upload_url: /ytgg_infoSys/info/SysClientAction_upload.do
flash_url: /ytgg_infoSys/uploadify/uploadify.swf?preventswfcaching=1375105680980
use_query_string: true
requeue_on_error: false
http_success:
assume_success_timeout: 30
file_post_name: uploadify
post_params: [object Object]
file_types: *.*
file_types_description: All Files
file_size_limit: 200KB
file_upload_limit: 5
file_queue_limit: 999
debug: true
prevent_swf_caching: true
button_placeholder_id: uploadify
button_placeholder: Not Set
button_image_url: /ytgg_infoSys/info/
button_width: 120
button_height: 30
button_text:
button_text_style: color: #000000; font-size: 16pt;
button_text_top_padding: 0
button_text_left_padding: 0
button_action: -110
button_disabled: false
custom_settings: [object Object]
Event Handlers:
swfupload_loaded_handler assigned: false
file_dialog_start_handler assigned: true
file_queued_handler assigned: true
file_queue_error_handler assigned: true
upload_start_handler assigned: true
upload_progress_handler assigned: true
upload_error_handler assigned: true
upload_success_handler assigned: true
upload_complete_handler assigned: true
debug_handler assigned: true
SWF DEBUG: SWFUpload Init Complete
SWF DEBUG:
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number: SWFUPLOAD 2.2.0
SWF DEBUG: movieName: SWFUpload_0
SWF DEBUG: Upload URL: /ytgg_infoSys/info/SysClientAction_upload.do
SWF DEBUG: File Types String: *.*
SWF DEBUG: Parsed File Types:
SWF DEBUG: HTTP Success: 0
SWF DEBUG: File Types Description: All Files (*.*)
SWF DEBUG: File Size Limit: 204800 bytes
SWF DEBUG: File Upload Limit: 5
SWF DEBUG: File Queue Limit: 5
SWF DEBUG: Post Params:
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
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
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to /ytgg_infoSys/info/SysClientAction_upload.do? for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 13192. Total: 13192
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 404.
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
SWF DEBUG: Event: AssumeSuccess: 30 passed without server response
换ie浏览器又报302错误,是sessionID的错误吗?怎么解决?
因为flash在浏览器中是第三方的插件,会导致sessionID丢失。
尝试下使用formData参数把{sessionName: sessionID} 带到后端,然后在后端的请求入口做下判断,如果存在sessionName并且值为sessionID,就把sessionID重新写入session
在这里AD一下,我写的一个上传插件,绝对比uploadify优秀,文件大小也小了一半。
是基于HTML5的,并且优雅降级到Flash,正好完美解决了这个问题