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;
        }
    }
  • 相关阅读:
    sql对日期操作
    computeroperationcommand
    Convert函数对日期的应用
    编写快速、高效的JavaScript代码
    vim常用操作技巧与配置
    PureFTPd安装配置
    关于PHP代码加密和文本加密
    父页面调用iframe里的js函数相关例程,Iframe之间通讯研究
    常用JavaScript语法100讲
    计算机端口
  • 原文地址:https://www.cnblogs.com/wuyou/p/3239513.html
Copyright © 2011-2022 走看看