设为首页 收藏本站
查看: 632|回复: 0

[经验分享] swfupload使用org.apache.commons.fileupload 实现上传文件

[复制链接]

尚未签到

发表于 2017-1-11 08:28:33 | 显示全部楼层 |阅读模式
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"  disabled="disabled" />
            <input id="btnCancel1" type="button" value="取消"  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>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-326739-1-1.html 上篇帖子: Apache Velocity DocBook Framework中文PDF生成攻略(三) 下篇帖子: apache的缓存mod_cache设置----待更新
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表