JAVA版-SWFUpload使用(包括传参问题)(一)

2014-11-24 08:32:02 · 作者: · 浏览: 5

官方的版本中只有php的版本,从网上找了其他人写的内容,自己实现了一个servlet的版本,
但是又出现另一个问题,如何向后台传递参数的问题,现在整理出来,以备忘。
问题:
1、编码问题,做的示例用的gb18030,所以后台很多的转码问题,采用UTF-8,能好一些,
2、传递中文问题,最好还是前台进行encoding,(encodeURI),后台进行解析取出来吧--未测试

上代码:
一、前台页面index.jsp

001
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
002

003
<%
004
String path = request.getContextPath();
005
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
006
%>
007

008

009

010

011

012

013
文件上传swfupload使用
014

015

016

017

018

019

022

023

024

025

026

027

028

029
<script type="text/java script">
030
var swfu;
031

032
SWFUpload.onload = function () {
033
var settings = {
034
flash_url : "<%=basePath%>swfupload/swfupload.swf",
035
flash9_url : "<%=basePath%>swfupload/swfupload_fp9.swf",
036
upload_url: "<%=basePath%>upload",
037
post_params: {
038
"hello" : "Here I Am",
039
"name" : "张三"
040
},
041
file_size_limit : "100 MB",
042
file_types : "*.*",
043
file_types_description : "All Files",
044
file_upload_limit : 100,
045
file_queue_limit : 0,
046
custom_settings : {
047
progressTarget : "fsUploadProgress",
048
cancelButtonId : "btnCancel"
049
},
050
debug: true,
051
use_query_string : true,//要传递参数,必须配置,可以从后台取到参数,应该还有其他方式,如post方式,未了解
052

053
// Button Settings
054
button_image_url : "<%=basePath%>images/TestImageNoText_65x29.png",
055
button_placeholder_id : "spanButtonPlaceholder",
056
button_width: 61,
057
button_height: 22,
058
button_text: '浏览',
059
button_text_style: ".spanButtonPlaceholder { font-size: 12; }",
060
button_text_left_padding: 12,
061
button_text_top_padding: 3,
062

063
// The event handler functions are defined in handlers.js
064
//swfupload_preload_handler : preLoad,
065
//swfupload_load_failed_handler : loadFailed,
066
file_queued_handler : fileQueued,
067
file_queue_error_handler : fileQueueError,
068
file_dialog_complete_handler : fileDialogComplete,
069
upload_start_handler : uploadStart,
070
upload_progress_handler : uploadProgress,
071
upload_error_handler : uploadError,
072
upload_success_handler : uploadSuccess,
073
upload_complete_handler : uploadComplete,
074
queue_complete_handler : queueComplete // Queue plugin event
075

076
};
077

078
swfu = new SWFUpload(settings);
079
}
080

081

082

083


084
文件列表:
085

086
上传了0个文件

087

088

089

090

091

092

093

094

095

096

097

098

099

100

二、前台接收后台返回数据的位置 --handler.js-只需要找到该位置,进行修改就可以了

01
function uploadSuccess(file, serverData) {
02
try {
03
var progress = new FileProgress(file, this.customSettings.progressTarget);
04
progress.setComplete();
05
progress.setStatus("上传完成.");
06
progress.toggleCancel(false);
07
alert(serverData);
08

09
//后台传递回来的内容
10
var serdata = document.getElementById("fi