4
我上传文件使用与jsp作为前端的struts 2,但我不想在文件上传后刷新页面,所以我使用的是Ajax但我无法获取File对象的动作,似乎文件上传需要在jsp中形成标签,并且如果我提交表单,那么页面会被刷新。 我通过网络进行了研究,但无法获得许多相关结果,如果有人引导我完成这个任务,这对我有很大的帮助。任何帮助真的会被赞赏。使用的struts2和iframe 问候文件上传与Ajax的struts 2
我上传文件使用与jsp作为前端的struts 2,但我不想在文件上传后刷新页面,所以我使用的是Ajax但我无法获取File对象的动作,似乎文件上传需要在jsp中形成标签,并且如果我提交表单,那么页面会被刷新。 我通过网络进行了研究,但无法获得许多相关结果,如果有人引导我完成这个任务,这对我有很大的帮助。任何帮助真的会被赞赏。使用的struts2和iframe 问候文件上传与Ajax的struts 2
我建议使用上传文件,而不是AJAX iframe中上传的CSV文件
示例代码:
var file = $("#fileUpload").val();
if(file.indexOf(".") != -1 && file.substr(file.indexOf("."))==".csv"){
/* created IFrame For UPload file*/
var iframe = $('<iframe name="uploadIPAddressIFrame" id="uploadIPAddressIFrame" style="display: none" />');
$("body").append(iframe);
/* Set Form for submit iframe*/
var form = $('#ipPoolForm');
form.attr("action", "uploadCSVFile.do");
form.attr("target", "uploadIPAddressIFrame");
form.submit();
openDialog(title);
/* handle response of iframe */
$("#uploadIPAddressIFrame").load(function() {
response = $("#uploadIPAddressIFrame")[0].contentWindow.document.body.innerHTML;
$("#chkIPAddressDiv").html(response);
$("iframe#uploadIPAddressIFrame").remove();
});
上传后,如果您提交表单,然后更改目标形式:
// Because of using iframe for upload set target value
$("#ipPoolForm").attr("target", "");
是否尝试该例子中[FileUploadUsingAjax](http://code.google.com/p/ajax-file-upload-struts2/downloads/list) – 2012-03-02 14:13:12
这些是罐子和压缩包,需要做什么,请你指导一下什么是适应流程? – 2012-03-02 14:23:39
@EricIlavia:遵循这个http://stackoverflow.com/questions/5270288/upload-file-in-struts2-using-ajax – 2012-03-02 17:15:43