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表单提交可自动解决编码问题

  • 相关阅读:
    CF1174D Ehab and the Expected XOR Problem
    CF1083B The Fair Nut and Strings
    CF1088D Ehab and another another xor problem
    CF1168A Increasing by Modulo
    CF1166C A Tale of Two Lands
    CF1142A The Beatles
    CF1105D Kilani and the Game
    【uva11248】网络扩容
    【sam复习】用sam实现后缀排序
    【Educational Codeforces Round 19】
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4344977.html
Copyright © 2011-2022 走看看