我创建了 Java Backed WebScript,它允许客户端通过 POST 上传文件。我可以成功上传文件,一切正常。但是我想在文件上传完成后立即离开,重定向到上传文档的文档详细信息页面。
是否可以使用 Java 代码调用重定向,或者有办法将 nodeRef 放入 WebScriptResponse 并从 Javascript 中读取它?目前我在 Alfresco 4.2.c 上工作。在我的 *.html.ftl 我有:
<form method="post" id="${id}-form" enctype="multipart/form-data" action="${action}" enctype="multipart/form-data">
<input type="file" name="fileField">
<span id="${id}-form-submit" class="yui-button yui-submit-button">
<span class="first-child">
<button type="button">${msg("button.upload")} </button>
</span>
在 .js 文件中:
this.widgets.submitButton = Alfresco.util.createYUIButton(this, "form-submit", null, {
type: "submit"
});
这是我的Java代码:
public class UploadWebScript extends AbstractWebScript
{
@Override
public void execute(final WebScriptRequest req, WebScriptResponse res)
{
FormData form = (FormData) req.parseContent();
for (FormData.FormField field : form.getFields())
{
String fileName = field.getFilename();
if (field.getIsFile())
{
/*...Some custom code for upoading document...
Here I have documentNodeRef of the uploaded document.
*/
}
}
res.getWriter().write("OK");
/* I can put here
res.getWriter().write(documentNodeRef.toString());
but I don't know how to access from Javascript. */
}
}