【问题标题】:need an example of using SWFUpload with java需要一个将 SWFUpload 与 java 一起使用的示例
【发布时间】:2010-05-27 15:12:40
【问题描述】:

我是 SWFUpload 的新手,我现在正在阅读文档,我需要一个使用 Java 的 SWFUpload 示例,谢谢。

【问题讨论】:

标签: swfupload


【解决方案1】:

SWFUpload、jQuery、JSP、Java 和 Spring 的示例实现

首先是jsp:

<%@ page language="java" pageEncoding="UTF-8" %>
<head>
<script type="text/javascript" src="<c:url value="/public/js/swfupload/swfupload.js"/>"></script>  
<script type="text/javascript" src="<c:url value="/public/js/jquery-plugins/ jquery.swfupload.js"/>"></script> 
<script type="text/javascript">
$(function(){
    $('.swfupload-control').swfupload({
        // Backend Settings
        upload_url: "<c:url value="/upload;jsessionid=${pageContext.session.id}"/>",    // Relative to the SWF file (or you can use absolute paths)

        // Flash Settings
        flash_url : "<c:url value="/public/js/swfupload/swfupload.swf"/>",

    //IMPORTANT: you need to set file_post_name otherwise flash sets it as Filedata, which does not conform to bean naming conventions. 
        file_post_name: "file",

        // File Upload Settings
        file_size_limit : "102400", // 100MB
        file_types : "*.*",
        file_types_description : "All Files",
        file_upload_limit : "10",
        file_queue_limit : "0",

        // Button Settings
        button_image_url : "<c:url value="/public/js/swfupload/XPButtonUploadText_61x22.png"/>", // Relative to the SWF file
        button_placeholder_id : "spanButtonPlaceholder",
        button_width: 61,
        button_height: 22



    });


    // assign our event handlers
    $('.swfupload-control')
        .bind('fileQueued', function(event, file){
            // start the upload once a file is queued
            $(this).swfupload('startUpload');
        })
        .bind('uploadComplete', function(event, file){
            alert('Upload completed - '+file.name+'!');
            // start the upload (if more queued) once an upload is complete
            $(this).swfupload('startUpload');
        });

}); 

</script>
<head>
<body>
<div id="file_upload"></div>
<div class="swfupload-control">
   <span id="spanButtonPlaceholder"></span>
</div>
</body>

控制器:

@Controller
public class UploadController {
Logger logger = LoggerFactory.getLogger(this.getClass());

@RequestMapping(value="/upload", method=RequestMethod.POST)
public String addMultiple(
    final HttpServletRequest request
    , final HttpServletResponse response
    , @RequestParam("file") MultipartFile file //NOTE: `@RequestParam("file")` matches `file_post_name: "file"`
    ){
        logger.debug(uploadedFile.getOriginalFilename());

    }
} 

另外,请确保你的配置中有这个:

<bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

</bean>

如果您不使用 spring,您可以将 HttpServeletRequest 转换为 MultiPartRequestWrapper 使用:

File[] files = ((MultiPartRequestWrapper)request).getFiles("Filedata");

此解决方案不需要 COS(Com O'Reilly Servlet)。相反,它只使用更常见的 javax.servlet.http.HttpServletRequest

来源(stackoverflow 不允许我发布链接):

  1. swfupload.org/forum/generaldiscussion/1087
  2. demo.swfupload.org/Documentation/#setFilePostName
  3. blogs.bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin/
  4. webdeveloperplus.com/jquery/multiple-file-upload-with-progress-bar-using-jquery/(更漂亮的 jquery 上传器实现)

【讨论】:

  • 哦,是的,请确保您从某个地方获取 XPButtonUploadText_61x22.png,否则按钮不会显示。
【解决方案2】:

http://e-blog-java.blogspot.com/2011/03/upload-using-swfupload-component.html

他还提供了一个示例源代码来查看它的运行情况。

【讨论】:

    猜你喜欢
    • 2016-02-09
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2016-12-12
    • 1970-01-01
    • 2018-12-18
    相关资源
    最近更新 更多