需要一个在Java中使用SWFUpload的示例 [英] need an example of using SWFUpload with java

查看:86
本文介绍了需要一个在Java中使用SWFUpload的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i am new to SWFUpload , and i am reading the documentation now, and i need an example using SWFUpload with java please, thank you.

推荐答案

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());

    }
} 

此外,请确保您已在配置文件中添加了此文件:

Also, make sure you've got this in your configs:

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

</bean>

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

If you are not using spring you might be able to cast the HttpServeletRequest as a MultiPartRequestWrapper use:

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

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

This solution doesn't require COS (Com O'Reilly Servlet). Instead it just uses the more common javax.servlet.http.HttpServletRequest

来源(stackoverflow不会让我发布链接):

Sources (stackoverflow wouldnt let me post links):

  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上传器的更佳实现)

这篇关于需要一个在Java中使用SWFUpload的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆