zoukankan      html  css  js  c++  java
  • Servlet的乱码处理手记

    前记            

          今天开学第二天,老师教了我们如何处理Servlet中的乱码。涵盖了所有乱码的处理。

            1、处理post方法传入的乱码
           -----修改servlet中的乱码
                  request.setCharacterEncoding("utf-8");
                 response.setCharacterEncoding("utf-8");
           ----设置页面展示的编码
                resp.setHeader("Content-type", "text/html;charset=UTF-8"); 
                 resp.setContentType("text/html;charset=utf-8");
         2、处理get方法传入数据乱码问题
              -----修改servlet中的乱码
                  request.setCharacterEncoding("utf-8");
                  response.setCharacterEncoding("utf-8");
           ----设置编码的转换
                  String name = new String(request.getParameter("userName").getBytes("iso8859-1"),"utf-8");
           ----设置页面展示的编码
                 resp.setHeader("Content-type", "text/html;charset=UTF-8"); 
                 resp.setContentType("text/html;charset=utf-8");
         修改get方法传入的乱码:
           可以通过修改tomcat中编码设置: tomcat/conf/server.xml文件

                原文是

                         <Connector port="8080" protocol="HTTP/1.1"  connectionTimeout="20000"  redirectPort="8443" />

                修改后:
                     <Connector port="8080" protocol="HTTP/1.1"  connectionTimeout="20000" redirectPort="8443" 
                           URIEncoding="utf-8"/>      

  • 相关阅读:
    Kafka日志及Topic数据清理
    python
    kotlin集合操作
    tomcat 下配置 可 调试
    linux 安装nexus3
    启动 idea 编译报错 kotlin
    nginx 增加 lua模块
    logstash配合filebeat监控tomcat日志
    redis 高级特性 不要太好用
    SpringBoot与Docker1
  • 原文地址:https://www.cnblogs.com/gmgyr/p/5791389.html
Copyright © 2011-2022 走看看