【发布时间】:2014-09-15 07:15:36
【问题描述】:
我使用 postgresql 作为后端。我在 case_attachments 表中保存了附件和附件标题。 当我点击下载附件时,它会下载它。但是附件名称是这样的 downloadAttachFile 和类型为 action 。我会保存多种类型的附件,例如 jpg、pdf、doc 等。因此,在下载时,文件名和扩展名正确很重要。
这是我的 struts.xml
<action name="downloadAttachFile" class="abc.actions.mypackage" method="downloadAttachFile">
<result name="success" type="stream">
<param name="contentType">application/octet-stream/text/plain/doc</param>
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;filename=%{AttachFileName}</param>
<param name="bufferSize">1024</param>
</result>
</action>
以及动作方法
public String downloadAttachFile() throws FileNotFoundException {
String AttachFileName = ServletActionContext.getRequest().getParameter("myFileFileName");
fileInputStream = new FileInputStream(new File(AttachFileName));
return SUCCESS;
}
当我右键单击并使用正确的工具打开它时,它会正确打开。所以这里唯一的问题是名称和扩展类型。
【问题讨论】:
标签: java postgresql struts2 download attachment