struts2文件名和内容类型为空,使用plupload上载
我得到的文件名为空,从plupload插件上传。如何获取原始文件名。请告诉我哪里错了 jspstruts2文件名和内容类型为空,使用plupload上载,struts2,plupload,Struts2,Plupload,我得到的文件名为空,从plupload插件上传。如何获取原始文件名。请告诉我哪里错了 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"%> <
<%@ 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>
根据给出的打印语句,我可以在控制台上看到这一点
o_17oq47949abc11n51pg11rnah06a.jpg
E:\Documents and Settings\Pluto\My Documents\NetBeansProjects\ShareApp\build\web\
c:\temp\upload__408094b5_13e30976641__7fea_00000003.tmp
null
null
这是我的struts配置中的问题吗?我正在使用注释,因此没有struts.xml文件。或者问题在于plupload发送文件名,因为当我检索name参数时,我得到了一些不同的名称“o_17oq47949abc11n51pg11rnah06a.jpg”,它不是实际的名称。如果是的话,我怎样才能得到原来的名字
感谢并问候我仍然不明白为什么您要使用所有这些插件来执行这么简单的操作。您是否需要
AJAX上传
?如果没有,您只需使用将一个或多个文件上载到操作,通过自动文件大小
检查、文件名
和内容类型
检测,只需在操作中声明三个前缀相同的变量:
行动代码:
private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
/* getters and setters */
JSP代码:
<s:file name="fileUpload" />
然后,您可以执行客户端(HTML5,带有javascript)文件大小检查、服务器端文件大小检查,并设置服务器端整体多部分请求大小(在Struts.xml中,您甚至在使用注释时都应该有)
您可以在此处阅读详细信息:
最后一个建议是:做一些简单有效的东西,然后开始定制/扩展它。现在就解决了。我在plupload
选项中设置唯一\u名称:false
。struts操作中的内容类型和文件名为null
。我使用getParameter(“name”)检索文件名代码>解决方案:
在struts.xml中添加fileupload interceoptor()
在action类中添加以下属性
private String[] fileFileName;
private String[] fileContentType;
private File[] file;
我知道我可以简单地使用s:form和s:file来完成它,而且我知道我可以做多个文件。我需要的是ajax上传和单字段上传,我的意思是,如果我想用struts的方式上传多个文件,那么我需要有多个s:file,我正在寻找要浏览的单文件字段和要上传的多个文件。希望你明白我需要什么。谢谢,而且我认为它自己的文件名正在被plupload更改。我还是不确定。你试过Struts2 jQuery插件吗?您总是需要一个s:文件,但只需使用jQuery上传它即可执行AJAX调用。这将是不同的上传与拖放,然后你需要写javascript的东西:实际上一切似乎都工作,而且我喜欢这个插件,所以只想使用它,唯一的问题是我没有得到原始文件名。最后在firebug中,我可以看到文件名在文章中更改。所以我认为现在它确认了插件本身正在更改文件名。
private String[] fileFileName;
private String[] fileContentType;
private File[] file;