请教一个struts2下载oracle数据库blob字段的问题

蓝翼星空 发布于 2017/02/28 14:23
阅读 102
收藏 0
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;
        }
    }

这是action

 

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;
}

这是service

 

<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>

这是配置文件

加载中
0
蓝翼星空
蓝翼星空

需求是弹出一个文件框可以自由选择路径并且保存。请问为什么不能正常弹出文件下载框并下载呢?求大神指点

0
蓝翼星空
蓝翼星空

。。。。没人啊

返回顶部
顶部