action:
public String download()
{
Long docId = Long.valueOf(RequestUtil.getParam(request, "docId", new Integer(0))).longValue();
try
{
inputStream = this.taDocumentService.downLoad(docId);
return SUCCESS;
}
catch (Exception e)
{
e.printStackTrace();
return ERROR;
}
}
service:
public InputStream downLoad(Long docId)
{
TaDocument taDocument = this.read(docId);
String filepath = "E:/" + taDocument.getDocName() +"."+ taDocument.getDocType();
InputStream inputStream = null;
try
{
Blob blob = taDocument.getDocContent();
if(blob != null)
{
inputStream = blob.getBinaryStream();
FileOutputStream file = new FileOutputStream(filepath);
int len = (int) blob.length();
byte[] buffer = new byte[len];
while ( (len = inputStream.read(buffer)) != -1)
{
file.write(buffer, 0, len);
}
file.close();
inputStream.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
return inputStream;
}
配置文件:
<package name="taDocument" namespace="/taDocument" extends="power-default">
<action name="*" class="com.power.web.action.manager.TaDocumentAction" method="{1}">
<result name="success" type="stream">
<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${attachmentFileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
</package>
请问为什么不能正常弹出文件下载框并下载呢?
给你两个链接参考一下吧:
http://www.ulewo.com/knowledge/1973
http://www.zuidaima.com/share/1550463402478592.htm
需求是弹出一个文件框可以自由选择路径并且保存。求大神指点
public String download()throws Exception{
Long docId = Long.valueOf(RequestUtil.getParam(request, "docId", new Integer(0))).longValue();
try
{
inputStream = this.taDocumentService.downLoad(docId);
return SUCCESS;
}
catch (Exception e)
{
e.printStackTrace();
return ERROR;
}
}