博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaWeb学习记录(三)——网页中文编码问题
阅读量:4563 次
发布时间:2019-06-08

本文共 907 字,大约阅读时间需要 3 分钟。

方法一:

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

你可能感兴趣的文章
没写完,没调完,咕咕咕的代码
查看>>
Android Studio使用技巧:导出jar包
查看>>
Problem E. TeaTree - HDU - 6430 (树的启发式合并)
查看>>
Kafka序列化和反序列化与示例
查看>>
win10下VS2010中文输入法切换为英文卡死
查看>>
retinex相关代码汇总
查看>>
Cortex-M3 异常返回值EXC_RETURN
查看>>
kettle 转换字段遇到问题(couldn't get row from result set)——摘
查看>>
nginx首页根据IP跳转
查看>>
【2019-08-20】有点目标,有点计划,有点目的
查看>>
【2019-09-10】美,真的跟年龄无关
查看>>
【2019-09-28】少,但更好
查看>>
【2019-09-13】耐心观察是一种技能
查看>>
mysql数据库2-常用命令
查看>>
安卓开发环境搭建(转)
查看>>
Harris角点检测
查看>>
Struts2的处理流程及为Action的属性注入值
查看>>
设计中最常用的CSS选择器
查看>>
Maven项目打包成可执行Jar文件
查看>>
nginx http proxy 正向代理
查看>>