0

对于通过 fckeditor 上传的文件,是否可以将 content-disposition 设置为“附件”?

4

2 回答 2

0

我不这么认为。仅适用于 DMS 中的资源。

于 2014-03-03T19:19:46.770 回答
0

实际上,我只是想出一个解决方法;添加一个 servlet 过滤器,将 http 标头属性更改content-dispositionattachment,就是这样!这是一个代码片段:

public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        StringBuffer fileName = new StringBuffer();
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        StringBuffer extension = new StringBuffer(
                FilenameUtils.getExtension(req.getRequestURL().toString()));

        log.debug("--***-- File extension : " + extension.toString());

        if (extension.toString().equalsIgnoreCase("pdf")
                || extension.toString().equalsIgnoreCase(".pdf")) {

            fileName.append(FilenameUtils.getBaseName(req.getRequestURL()
                    .toString()));

            log.debug("--***-- PDF file name : " + fileName.toString());

            resp.addHeader("Content-Disposition", "attachment; filename="
                    + fileName);
        }

        chain.doFilter(request, resp);


    }
于 2014-03-05T07:43:24.110 回答