0

I am getting file name in action as null, uploaded from plupload plugin. how can i get the original file name. Please tell where is my mistake.

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<title>test</title>
<sj:head compressed="false"/>
<link rel="stylesheet" type="text/css" href="plup/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />
<script type="text/javascript" src="plup/plupload.full.min.js"></script>
<script type="text/javascript" src="plup/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript">
/* Convert divs to queue widgets when the DOM is ready */
$(function(){
    function plupload(){
        $("#uploader").pluploadQueue({
            // General settings
            runtimes : 'html5,gears,browserplus,silverlight,flash,html4',
            url : 'uploads',
            max_file_size : '10mb',
            unique_names : true,
            chunk_size: '2mb',
            // Specify what files to browse for
            filters : [
                {title: "Image files", extensions: "jpg,gif,png"},
                {title: "Zip files", extensions: "zip"}
            ],
            resize: {width: 320, height: 240, quality: 90},

            // Flash settings
            flash_swf_url : 'plup/Moxie.swf',
            // Silverlight settings
            silverlight_xap_url : 'plup/Moxie.xap',
            multipart_params: {'user': 'admin', 'time': '2012-06-12'}
        });
    }
    plupload();
    $('#clear').click(function(){
        plupload();
    });
});
</script>

</head>

<body>
    <div>
        <div style="width: 750px; margin: 0px auto">
            <form id="formId" action="submit.action" method="post">
                <div id="uploader">
                    <p>Flash, Silverlight, Gears, BrowserPlus,HTML5 .</p>
                </div>
                <input type="button" value="Clear" id="clear"/>
            </form>
        </div>
    </div>
</body>

</html>

Action

@Action(value="plupUploaduploads")
        public String upload() throws Exception {
                isMultipart = ServletFileUpload.isMultipartContent(getReq());
                System.out.println(getReq().getParameter("value"));
                ServletContext servletContext = getReq().getServletContext();
                String filePath = servletContext.getRealPath("/");
                System.out.println(filePath);
                System.out.println(this.file);
                System.out.println(this.fileName);
                System.out.println(this.contentType);
                File theFile = new File("c:\\",this.getFileName());  
                FileUtils.copyFile(file,theFile); 
        return SUCCESS;
    }

//getters and setters

i can see this on console according to print statements given.

o_17oq47949abc11n51pg11rnah06a.jpg
E:\Documents and Settings\Pluto\My Documents\NetBeansProjects\ShareApp\build\web\
c:\temp\upload__408094b5_13e30976641__7fea_00000003.tmp
null
null

is it the problem in my struts config? I am using annotations hence dont have struts.xml file. Or the problem is in plupload sending the file name, because when i retrived the name parameter i am getting some different name "o_17oq47949abc11n51pg11rnah06a.jpg" which is not the actual name. If so how can i get the original name?

Thanks and regards

4

3 回答 3

1

我仍然不明白你为什么要使用所有这些插件来执行如此简单的操作。你需要AJAX upload吗?如果没有,您可以简单地使用<s:file /> 将一个或多个文件上传到 Action,并自动filesize检查filenamecontenttype检测,只需在您的 Action 中声明三个具有相同前缀的变量:

动作代码:

private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
/* getters and setters */

JSP代码:

<s:file name="fileUpload" />

然后,您可以执行客户端(HTML5,使用 javascript)文件大小检查、服务器端文件大小检查,并设置服务器端整体多部分请求大小(在 Struts.xml 中,即使使用注释也应该具有)。

您可以在此处阅读详细信息:struts2 s:form 元素修剪 action 属性中的 s:url 参数

作为最后的建议:做一些简单的工作,然后开始定制/扩展它。

于 2013-04-22T11:47:03.767 回答
0

Solution:

Add fileupload interceoptor in struts.xml (< interceptor-ref name="fileUpload" />)

Add the following properties in the action class.

    private String[] fileFileName;

    private String[] fileContentType;

    private File[] file;
于 2013-06-20T11:18:29.803 回答
0

现在解决了。我设置unique_names : falseplupload选项。内容类型和文件名null在 struts 动作中。我使用getParameter("name");.

于 2013-04-23T07:31:56.410 回答