谁有SWFUpload上传文件的例子,急用,谢谢! 我现在在做一个SWFUpload 上传,谁有这方面的经验,能请教一下吗?或者给一个上传的例子。谢谢了,很急用! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package com.techmore.struts.action;import java.io.File;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.UUID;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileItemFactory;import org.apache.commons.fileupload.disk.DiskFileItemFactory;import org.apache.commons.fileupload.servlet.ServletFileUpload;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.MappingDispatchAction;/** * MyEclipse Struts Creation date: 05-18-2007 * * XDoclet definition: * * @struts.action validate="true" */public class UploadFilesAction extends MappingDispatchAction { /* * Generated Methods */ /** * Method execute * * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub System.out.println("xxx"); // request.setAttribute(arg0, arg1) try { request.setCharacterEncoding("UTF-8"); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); // upload.setHeaderEncoding(request.getCharacterEncoding()); System.out.println("request:" + request); List items = upload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) {/* * String name = item.getFieldName(); String value = item.getString(); * System.out.println("name = " + name); System.out.println("value = " + * value); System.out.println("/r/n"); */ } else { String fieldName = item.getFieldName(); String fileName = item.getName(); System.out .println("鏂囦欢绫诲瀷 " + fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())); // boolean isInMemory = item.isInMemory(); long sizeInBytes = item.getSize(); getListInSession(request).add(fileName); getListInSession(request).add(UUID.randomUUID()); // String[] str=fieldName.split("\\."); // int l=str.length-1; // System.out.println("鏂囦欢绫诲瀷 "+str[l]); // System.out.println("fieldName = " + fieldName); System.out.println("fileName = " + fileName); // System.out.println("鏂囦欢瀛樺偍璺緞 "+request.getRealPath("/")+"uploadfile/"); // 璺緞 D:\Program Files\apache-tomcat-6.0.18\webapps\rockontrol_oa\UploadFiles\2009042991039312\ String filePath = this.getServlet().getServletContext().getRealPath("/") + "uploadfile/" + "涓枃/"; File savePath = new File(filePath); System.out.println(savePath.getAbsolutePath()); if (!savePath.exists()) { savePath.mkdir(); } item.write(new File(filePath + fileName)); } } System.out.println("-------- final--------"); } catch (Exception ex) { ex.printStackTrace(); } return null; } public ActionForward getResult(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List list = getListInSession(request); request.getSession().removeAttribute("_result"); response.setCharacterEncoding("utf-8"); response.getWriter().print(list); response.flushBuffer(); return null; } public List getListInSession(HttpServletRequest request) { List result = (List) request.getSession().getAttribute("_result"); if (result == null) { result = new ArrayList(); request.getSession().setAttribute("_result", result); } return result; }}/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package com.techmore.struts.form;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.upload.FormFile;/** * MyEclipse Struts * Creation date: 05-18-2007 * * XDoclet definition: * @struts.form name="uploadForm" */public class UploadForm extends ActionForm { /* * Generated Methods */ private FormFile uploadFileData; public FormFile getUploadFileData() { return uploadFileData; } public void setUploadFileData(FormFile uploadFileData) { this.uploadFileData = uploadFileData; } /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub return null; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub }}<!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 - Simple Demo</title><link href="css/default.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="js/swfupload.js"></script><script type="text/javascript" src="js/swfupload.queue.js"></script><script type="text/javascript" src="js/fileprogress.js"></script><script type="text/javascript" src="js/handlers.js"></script><script type="text/javascript"> var swfu; window.onload = function() { var settings = { flash_url : "js/swfupload.swf", upload_url: "jscripts/uploadFile.do", post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"}, 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 : "btnCancel" }, debug: false, // Button settings button_image_url: "images/TestImageNoText_65x29.png", 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_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, queue_complete_handler : queueComplete // Queue plugin event }; 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>Simple Demo</h2> <form id="form1" action="index.php" method="post" enctype="multipart/form-data"> <p>This page demonstrates a simple usage of SWFUpload. It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p> <div class="fieldset flash" id="fsUploadProgress"> <span class="legend">Upload Queue</span> </div> <div id="divStatus">0 Files Uploaded</div> <div> <span id="spanButtonPlaceHolder"></span> <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" /> </div> </form></div></body></html> http://www.cnblogs.com/peaceli/archive/2009/01/16/1377198.html 里面有代码。。 我试着用过,里面的文件进IO过程中取消有问题,然后删除时只可以删一个不过这个好改 还有就是上传大小为零的文件时提示图标有时有有时没有 代码强大的一塌糊涂,你要是能整明白就好了 http://xueshuanglong.javaeye.com/blog/387567 如何使用jquery组装字符串 ASP.NET空间图片上传问题(用javascript),求高手帮助 javascript如何屏蔽鼠标双击,或将双击变成单击? 不能变换LOGO问题,求帮助? 脚本如何实现点击表格某行就将内容复制到文本框中? select multiple 的问题 请问,如何让一个TABLE完全不可见 (急)removeNode()方法每次只能移除 一组对象中的1/2???怪 100分求解图层移动问题,有点难度! check 数组问题 一个INNERHTML的问题 从页面代码中怎么找不到 图片 URL? 神奇啦
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.techmore.struts.action;import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;/**
* MyEclipse Struts Creation date: 05-18-2007
*
* XDoclet definition:
*
* @struts.action validate="true"
*/
public class UploadFilesAction extends MappingDispatchAction {
/*
* Generated Methods
*/ /**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub
System.out.println("xxx");
// request.setAttribute(arg0, arg1)
try {
request.setCharacterEncoding("UTF-8");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setHeaderEncoding(request.getCharacterEncoding());
System.out.println("request:" + request);
List items = upload.parseRequest(request); Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next(); if (item.isFormField()) {/*
* String name = item.getFieldName(); String value = item.getString();
* System.out.println("name = " + name); System.out.println("value = " +
* value); System.out.println("/r/n");
*/
} else {
String fieldName = item.getFieldName(); String fileName = item.getName();
System.out
.println("鏂囦欢绫诲瀷 " + fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length()));
// boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
getListInSession(request).add(fileName);
getListInSession(request).add(UUID.randomUUID()); // String[] str=fieldName.split("\\.");
// int l=str.length-1;
// System.out.println("鏂囦欢绫诲瀷 "+str[l]);
//
System.out.println("fieldName = " + fieldName);
System.out.println("fileName = " + fileName);
// System.out.println("鏂囦欢瀛樺偍璺緞 "+request.getRealPath("/")+"uploadfile/");
// 璺緞 D:\Program Files\apache-tomcat-6.0.18\webapps\rockontrol_oa\UploadFiles\2009042991039312\
String filePath = this.getServlet().getServletContext().getRealPath("/") + "uploadfile/" + "涓枃/";
File savePath = new File(filePath);
System.out.println(savePath.getAbsolutePath());
if (!savePath.exists()) {
savePath.mkdir();
}
item.write(new File(filePath + fileName)); }
}
System.out.println("-------- final--------");
} catch (Exception ex) {
ex.printStackTrace();
} return null;
} public ActionForward getResult(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
List list = getListInSession(request);
request.getSession().removeAttribute("_result"); response.setCharacterEncoding("utf-8");
response.getWriter().print(list);
response.flushBuffer(); return null;
} public List getListInSession(HttpServletRequest request) {
List result = (List) request.getSession().getAttribute("_result");
if (result == null) {
result = new ArrayList();
request.getSession().setAttribute("_result", result);
}
return result; }}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.techmore.struts.form;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;/**
* MyEclipse Struts
* Creation date: 05-18-2007
*
* XDoclet definition:
* @struts.form name="uploadForm"
*/
public class UploadForm extends ActionForm {
/*
* Generated Methods
*/
private FormFile uploadFileData;
public FormFile getUploadFileData() {
return uploadFileData;
} public void setUploadFileData(FormFile uploadFileData) {
this.uploadFileData = uploadFileData;
} /**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
} /**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
}
<!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 - Simple Demo</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload.queue.js"></script>
<script type="text/javascript" src="js/fileprogress.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript">
var swfu; window.onload = function() {
var settings = {
flash_url : "js/swfupload.swf",
upload_url: "jscripts/uploadFile.do",
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
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 : "btnCancel"
},
debug: false, // Button settings
button_image_url: "images/TestImageNoText_65x29.png",
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_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,
queue_complete_handler : queueComplete // Queue plugin event
}; 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>Simple Demo</h2>
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p>This page demonstrates a simple usage of SWFUpload. It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p> <div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div> </form>
</div>
</body>
</html>
里面有代码。。
我试着用过,里面的文件进IO过程中取消有问题,然后删除时只可以删一个不过这个好改
还有就是上传大小为零的文件时提示图标有时有有时没有
代码强大的一塌糊涂,你要是能整明白就好了