[英]how activate action in struts2 using jquery file upload plugin
I am working on a project only needs one file upload at a time. 我正在做一个项目,一次只需要上传一个文件。 And I am using struts2 and jquery file upload plugin.
我正在使用struts2和jquery文件上传插件。 I see many examples but I don't know how to activate struts2 action in jquery file upload function.
我看到了很多示例,但我不知道如何在jquery文件上传功能中激活struts2动作。
This is my jsp 这是我的jsp
<form id="uploadForm" action="/myapp/trading_upload.action" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-9">
<div class="panel">
<div class="panel-heading">
<span class="panel-title">Upload</span>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Select file</span>
<input id="fileupload" type="file" name="files">
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
This is my js, basically it's just the jQuery File Upload example code 这是我的js,基本上只是jQuery File Upload示例代码
$(function() {
$('#fileupload').fileupload({
dataType: 'json',
url: '/myapp/trading_upload.action',
add: function (e, data) {
data.context = $('<button/>').text('Upload')
.appendTo(document.body)
.click(function () {
data.context = $('<p/>').text('Uploading...').replaceAll($(this));
data.submit();
});
},
done: function (e, data) {
consolo.log('complete');
alert("complete");
data.context.text('Upload finished.');
}
});
});
And this is my struts.xml 这是我的struts.xml
<action name="trading_upload" class="tradingAction" method="upload">
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
</interceptor-ref>
</action>
This is my tradingAction, it's just a print since I want to see it's activated 这是我的tradingAction,这只是打印,因为我想看到它已被激活
public String upload() throws Exception {
System.out.println("upload");
return SUCCESS;
}
Should I use url: '/myapp/trading_upload.action' to activate action? 我应该使用网址:“ / myapp / trading_upload.action”来激活操作吗? But after I select file nothing happen.
但是,选择文件后,什么都没有发生。 No action is activated.
没有激活任何动作。 Thanks in advance!
提前致谢!
Finally I realized I need to implement struts2 upload first, then I can combine it with file upload plugin to activate the action. 最后,我意识到我需要先实现struts2上传,然后再将其与文件上传插件结合起来以激活操作。 And it works
而且有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.