GET和POST乱码解决

乱码问题解决:

        * POST请求乱码 :

      request.setCharacterEncoding("utf-8");

 

         * GET请求乱码

                     解决方案一:修改tomcat/conf/server.xml

                                <Connector port="80" protocol="HTTP/1.1"

                                            connectionTimeout="20000"

                                            redirectPort="8443" URIEncoding="utf-8"/>

                                   * 必须有修改tomcat服务器配置文件权限

 

                      解决方案二:逆向编解码

                                   username = URLEncoder.encode(username, "ISO8859-1");

                                   username = URLDecoder.decode(username, "utf-8");

 

                      解决方案三:简写的方式(推荐使用)

                                   username = new String(username.getBytes("ISO-8859-1"),"utf-8");

                                  

                     * request获取中文数据乱码(总结:)

                                   * post提交

                                          * 设置request缓冲区的编码

                                                 request.setCharacterEncoding("utf-8");

                                   * get提交

                                          * String构造方法

              username = new String(username.getBytes("ISO-8859-1"),"utf-8");

posted on 2019-06-18 22:09  backend  阅读(502)  评论(0编辑  收藏  举报

导航