zoukankan      html  css  js  c++  java
  • struts2文件下载 火狐浏览器的文件名乱码问题

    这是一个文件下载的action,红色部分为火狐浏览器需要特地做的事情。

    @Controller
    @Scope(value = "prototype")
    public class FormManage_downloadAction {
    
        private String fileName;//下载文件时候的名称
        private String filePath;//文件在磁盘的路径
    
        public String execute() throws UnsupportedEncodingException {
            System.out.println("下载action");
            System.out.println("fileName="+fileName);
            System.out.println("filePath="+filePath);
    
            HttpServletRequest request = ServletActionContext.getRequest();
            String Agent = request.getHeader("User-Agent");
            if (null != Agent) {
                Agent = Agent.toLowerCase();
                if (Agent.contains("firefox")) {
                    System.out.println("火狐浏览器");
                    fileName = new String(fileName.getBytes(), "iso8859-1");
                } else {
                    System.out.println("非火狐浏览器");
                    fileName = URLEncoder.encode(fileName, "utf8");
                }
            }
            return "success";
        }
    
        public InputStream getInputStream() throws FileNotFoundException {
            return new FileInputStream(filePath);
        }
    
        public String getFileName() {
            return fileName;
        }
    
        public String getFilePath() {
            return filePath;
        }
    
        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
    
        public void setFilePath(String filePath) {
            this.filePath = filePath;
        }
    }
  • 相关阅读:
    smarty-2014-02-28
    PHP Functions
    Zabbix自定义监控网站服务是否能够正常响应
    Zabbix自定义监控网站服务是否能够正常响应
    shell技巧
    shell技巧
    ansible安装配置zabbix客户端
    ansible安装配置zabbix客户端
    shell命令getopts
    shell命令getopts
  • 原文地址:https://www.cnblogs.com/wuyou/p/3239513.html
Copyright © 2011-2022 走看看