我正在尝试在 struts 2 应用程序中实现这个插件。我能够将文件发送到服务器,但是当我使用正确的 div 响应操作时,我得到一个空白页面,其中只有当前年份作为内容。在 IE 中我得到:
Message: Permission denied
Line: 4
Char: 2462
Code: 0
URI: https://blah.blee.blah.ca/js/jquery/js/jquery-1.7.2.min.js
每当我刷新页面(显示 2012 的页面,我首先单击返回)然后重新加载页面时,我看到该文件在服务器上。
这是我的 JSP 片段
<div id="main_container">
<form action="uploadFile" method="post" enctype="multipart/form-data">
<input type="file" name="pdffile" class="fileUpload" multiple />
<button id="px-submit" type="submit">Save</button>
<button id="px-clear" type="reset">Clear</button>
</form>
<script type="text/javascript">
jQuery(function($) {
$('.fileUpload').fileUploader({
limit : 1,
autoUpload : false,
selectFileLabel : 'Select',
buttonUpload : '#px-submit',
buttonClear : '#px-clear',
allowedExtension : 'pdf'
});
});
</script>
</div>
支柱2动作:
public String uploadFile() {
String result = Action.ERROR;
String status = null;
if (log.isDebugEnabled()) {
log.debug("doUpload()");
}
try {
showAttachmentDiv = true;
if (log.isDebugEnabled()) {
log.debug("doUpload() with filename: '" + this.filename
+ "' and contentType '" + this.contentType + "'");
if (uploadedFile != null) {
log.debug("doUplaod() with file.getAbsolutePath(): "
+ uploadedFile.getAbsolutePath());
} else {
log.debug("doUplaod() with file: null ");
}
}
if (uploadedFile != null) {
if (this.getActionErrors().size() == 0) {
AttachmentsUIObject attachment = new AttachmentsUIObject();
// the file object is eventually deleted by the fileUpload
// utility, so we just copy it.
File copiedFile = copyFile(uploadedFile);
attachment.setFile(copiedFile);
attachment.setType(this.uploadAttachmentType);
attachment.setOriginalFilename(this.filename);
attachmentsList.add(attachment);
// save file code here
status = getText(DIV_MESSAGE_UPLOAD_SUCCESS); // on
// success
// inputStream = new StringBufferInputStream(status);
} else {
uploadedFile.delete();
status = getText(DIV_MESSAGE_UPLOAD_FAIL,
new String[] { getActionErrors().toString() });
}
result = Action.SUCCESS;
} else {
addActionError(getText("validation.file.missing"));
result = Action.INPUT;
}
} catch (Exception e) {
log.error("doUpload()", e);
addActionError(getText("error.uploadfailed"));
status = getText(DIV_MESSAGE_UPLOAD_FAIL,
new String[] { getText("error.uploadfailed") }); // on
result = BaseAction.ERROR_UPLOAD;
}
inputStream = new StringBufferInputStream(status);
return result;
}
struts 2 xml配置:
<action name="uploadFile" method="uploadFile" class="xxx.SubmitAction">
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
一个重要的注意事项。有甲骨文网络中心。这个 struts 2 应用程序是从门户访问的。这可能与此有关吗?