zoukankan      html  css  js  c++  java
  • JavaWeb学习记录(三)——网页中文编码问题

    方法一:

    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
        
            OutputStream os=response.getOutputStream();
            os.write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>".getBytes());
            os.write("我爱我家".getBytes());
            os.close();
            
        }

    方法二:

    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out=response.getWriter();
            out.write("我爱我家");
            out.close();
        }
    方法三:(上传文件时,火狐浏览器的中文转码问题)

    response.setHeader("Content-Disposition","attachment;filename*=utf-8'zh_cn'"+URLEncoder.encode(
                                file.getName().substring(file.getName().lastIndexOf("_") + 1),"UTF-8"));

    方法四:(struts下载文件时,火狐浏览器的中文转码问题)

    this.fileName = new String(fileName.getBytes(), "ISO8859-1");

    方法五:使用jsp表单提交可自动解决编码问题

  • 相关阅读:
    groovy 执行shell
    expect 用法
    shebang解释
    docker 安装
    centos7 lvm添加硬盘后扩展磁盘空间
    scoped的原理和deep深度选择器的妙用
    swagger3
    帮评网
    反射工具
    网络只能传输二进制
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4344977.html
Copyright © 2011-2022 走看看