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

原文地址:https://www.cnblogs.com/ly-radiata/p/4344977.html