ssi 文件下载(注解方式)

@Action(
            value = "DownloadOperationDoc",
            results = {
                    @Result(name = "success", type = "stream",
                            params = {"contentType",
                                    "application/octet-stream;charset=UTF-8", "inputName",
                                    "InputStream",
                                    "contentDisposition",
                                    "attachment;filename=\"${headerFileName}\"",
                                    "bufferSize", "4096"}),
                    @Result(name = "login", location = "/pages/welcome.jsp"),
            }
    )
    public String DownloadOperationDoc() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        @SuppressWarnings("unused")
HttpServletResponse response = ServletActionContext.getResponse();
//        response.addHeader( "Content-Disposition", "attachment;filename=\"${fileName}\"",);
        HttpSession session = request.getSession();
        setLoggedIn((String) session.getAttribute("loggedIn"));
        if (getLoggedIn() == null) {
            setMessage("请登录!");
            return LOGIN;
        }
        return SUCCESS;
    }

 

//

    public InputStream getInputStream() throws Exception {
        String fileName = ServletActionContext.getRequest().getParameter("fileName");
        IFile iFile = OuterFileUtil.getFile(fileName);
        return OuterFileUtil.getInputStream(iFile);

    }


//下载的文件名 

@SuppressWarnings("unused")
private String headerFileName;


    public String getHeaderFileName() {
        try {
//            return java.net.URLEncoder.encode( fileName, "UTF-8");
//            fileName = new String((main.getWwmWorkflowName()+"_"+time+".xml"));
//            getHttpResponse().setCharacterEncoding("UTF-8");
//            fileName=java.net.URLEncoder.encode(fileName,"UTF-8");
//            getHttpResponse().setHeader("Content-Disposition", "attachment; filename=" +new String(fileName.getBytes("UTF-8"),"GBK"));
        HttpServletRequest request = ServletActionContext.getRequest();
            String fileState = request.getParameter("fileState");
            System.out.println("#################"+fileState);
            String encodedFileName = "";
            if("1".equals(fileState)){
            int index = fileName.lastIndexOf("."); 
            String reName = fileName.substring(0,(index-36))+fileName.substring(index);
            encodedFileName = java.net.URLEncoder.encode( reName, "UTF-8");
            }else{
            encodedFileName = java.net.URLEncoder.encode( fileName, "UTF-8");
            }
       
            return new String(encodedFileName.getBytes("UTF-8"),"GBK");
//            return new String(encodedFileName.getBytes("UTF-8"), "ISO8859-1");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值