swfupload使用org.apache.commons.fileupload 实现上传文件

swfupload使用org.apache.commons.fileupload 实现上传文件,
详细附件,wtp工程。
其中:swf2/eidemo.jsp 实现界面,submit.jsp实现文件上传,文件传到temp目录下
<%@ page contentType="text/html;charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SWFUpload Demos - External Interface Demo</title>
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../swfupload/swfupload.js"></script>
<script type="text/javascript" src="fileprogress.js"></script>
<script type="text/javascript" src="handlers.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var swfu;
var total=0;
window.onload = function() {
var settings = {
flash_url : "../swfupload/swfupload.swf",
upload_url: "<%=request.getContextPath()%>/submit.jsp", // Relative to the SWF file
post_params: { "ChannelID": "28", "Type": "Type2" },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel1",
startButton:"startButton",
percentage:"percentage"
},
debug: false,

// Button settings
button_image_url: "TestImageNoText_65x29.png", // Relative to the Flash file
button_width: "65",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">Hello</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,

// The event handler functions are defined in handlers.js
file_dialog_start_handler : fileDialogStart,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete
};

swfu = new SWFUpload(settings);
     };
</script>
</head>
<body>
<div id="header">
<h1 id="logo"><a href="../">SWFUpload</a></h1>
<div id="version">v2.2.0</div>
</div>

<div id="content">
<h2>External Interface Demo</h2>
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p> This page tests rebuilding the External Interface after some kind of display change.  This demo isn't meant for building upon. Rather it
helps test whether a particular browser is suffering from this bug.</p>

<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div id="percentage">0 Files Uploaded</div>
<div id="divMovieContainer">
<span id="spanButtonPlaceHolder"></span>
</div>
<input type="button" value="Start Upload" id="startButton" onclick="swfu.startUpload();" disabled="disabled" />
            <input id="btnCancel1" type="button" value="取消" onclick="cancelQueue(swfu);" disabled="disabled"/>



</form>
</div>
</body>
</html>
submit.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="java.util.*,java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<%
String channel=request.getParameter("channel");
System.out.println("test up:"+channel);
DiskFileUpload upload = new DiskFileUpload();
String tempPath = request.getRealPath("/temp");
upload.setSizeThreshold(16000);
upload.setSizeMax(-1);
upload.setRepositoryPath(tempPath);

java.util.List items;

items = upload.parseRequest(request);
java.util.Iterator iter = items.iterator();
String ChannelID="";
String Type="";
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();

    if (item.isFormField()) {
String FieldName = item.getFieldName();
if(FieldName.equals("ChannelID"))
ChannelID = item.getString();
if(FieldName.equals("Type"))
Type = item.getString();
    }
}

iter = items.iterator();
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    if (!item.isFormField()) {
String FieldName = item.getFieldName();
String FileName = item.getName();
String FileExt = "";

FileName = FileName.substring(FileName.lastIndexOf("\\")+1);

int index = FileName.lastIndexOf(".");
if(index!=-1)
{
FileExt = FileName.substring(index+1);
}
System.out.println("ChannelID="+ChannelID);
System.out.println("path="+tempPath);

if(!FileName.equals(""))
{
File uploadedFile = new File(tempPath+"\\"+FileName);
    item.write(uploadedFile);

}
    }
}
%>
</center>
</body>
</html>

你可能感兴趣的:(apache,html,jsp,XHTML,Flash)