@ResponseBody
@RequestMapping(value = "companyTypeRelation/toupload")
public String uploadCompanyTypeRelation(
@RequestParam(value = "uploadfile", required = false) MultipartFile[] uploadfile,
HttpServletRequest request,HttpServletResponse response) {
// do logic
}
我使用ajax发送;但我发现MultipartFile为null,我可以得到该值;我不知道如何解决它? 下面是jsp详细信息:
<div class="upload" id="uploadDIV" title="upload"
style="text-align: center; display: none; padding: 5px;">
<center>
<a href="${pageContext.request.contextPath }/report/Excels/blalist.xls">uploadupload</a>
<form
action="${pageContext.request.contextPath }/backend/basic/companyTypeRelation/toupload"
id="UploadForm" method="post" enctype="multipart/form-data">
<br />
<input type="file" id="uploadfile" name="uploadfile"></input>
</form>
</center>
</div>
我使用ajax发送文件格式到服务器,也许有问题,但我不明白:
enter code here
$("#uploadDIV").dialog({
autoOpen : false,
height : 200,
width : 450,
modal : true,
buttons : {
"commit" : function() {
var filepath = document
.getElementById("uploadfile").value;
var re_text = /\xls/i;
var newFileName = filepath.split('.');
newFileName = newFileName[newFileName.length - 1];
if (newFileName.search(re_text) == -1) {
return;
}
var resourceURL = '${pageContext.request.contextPath}/backend/basic/companyTypeRelation/toupload';
//$("#UploadForm").submit();
$.ajax({
url:resourceURL,
type: 'POST',
data: {
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$(".validateTips").text("...");
},
success: function(data){
alert(data);
}
});
},
"cancel" : function() {
$(this).dialog("close");
}
},
close : function() {
allFields.val("").removeClass(
"ui-state-error");
}
});