zoukankan      html  css  js  c++  java
  • Tomcat

    tomcat_8 以前的版本编码格式为iso-8859-1 get请求中文乱码,需要在tomcat的server.xml文件中增加UTF-8 编码,

     

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>

     

    tomcat_8 编码格式是 UTF-8 所以不需要修改

     

     

    Tomcat真正跑的目录

    validateJarFile(/Users/wenyunli/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/biz-oss-base

     

     

     彻底解决Spring MVC 中文乱码问题

     

    1:表单提交controller获得中文参数后乱码解决方案

    注意:  jsp页面编码设置为UTF-8

    form表单提交方式为必须为postget方式下面spring编码过滤器不起效果

     

    [html] view plain copy

     

    1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  

    [html] view plain copy

     

    1. <form action="${ctx}/user/addUser" name="userForm" method="post">    

     

     

    修改web.xml,增加编码过滤器,如下(注意,需要设置forceEncoding参数值为true

     

    [html] view plain copy

     

    1. <filter>  
    2.         <filter-name>characterEncodingFilter</filter-name>  
    3.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
    4.         <init-param>  
    5.             <param-name>encoding</param-name>  
    6.             <param-value>UTF-8</param-value>  
    7.         </init-param>  
    8.         <init-param>  
    9.             <param-name>forceEncoding</param-name>  
    10.             <param-value>true</param-value>  
    11.         </init-param>  
    12.     </filter>  
    13.     <filter-mapping>  
    14.         <filter-name>characterEncodingFilter</filter-name>  
    15.         <url-pattern>/*</url-pattern>  
    16.     </filter-mapping>  

     

    截图

     

     

     

    tomcat 8 

    https://tomcat.apache.org/tomcat-8.0-doc/config/http.html

     

    This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, UTF-8 will be used unless the org.apache.catalina.STRICT_SERVLET_COMPLIANCE system property is set to true in which case ISO-8859-1 will be used.

     

    tomcat 7

     

    tomcat的 post和get解码方式是不一致的, 所以post没问题,保持编码和解码一致就行了,

    不要使用这种方式对参数进行编码  new String(value.getBytes(“ISO-8859-1”), param); Tomcat7对URI默认编码是ISO-8859-1,Tomcat8对URI默认编码是UTF-8 

    使用new String(value.getBytes(“ISO-8859-1”), param);这种方式对tomcat7 可以解决get乱码问题, 如果迁移到tomcat8就有问题了  

    正确的行为:server.xml配置上URIEncoding=“UTF-8”

     

    tomcat中,保证get数据采用UTF8编码,在server.xml中进行了如下设置:

    加:URIEncoding="UTF-8"

     

    <Connector port="8080" maxThreads="150"minSpareThreads="25"

    maxSpareThreads="75" enableLookups="false"redirectPort="8443"

    acceptCount="100" debug="99" connectionTimeout="20000"

    disableUploadTimeout="true"URIEncoding="UTF-8"/>

     

    指定了get时候的数据编码。当使用IIS作为webserver转发servlet/jsp请求给Tomcat时候,这个设置却失效

    其实原因很简单:IIS是通过AJP协议,把请求转发到Tomcat监听的8009端口上的,所以这里针对8080的设置自然就无效

    正确的方法是进行下面的设置:

    <Connector port="8009" enableLookups="false"redirectPort="8443"

    debug="0" protocol="AJP/1.3"URIEncoding="UTF-8"/>

     

    查看8080端口的进程:

     lsof -i:8080

    杀进程

    kill -9 PID

  • 相关阅读:
    做接口测试最重要的知识点
    HTTP和HTTPS区别
    UVA, 686 Goldbach's Conjecture (II)
    UVA, 543 Goldbach's Conjecture
    UVA, 580 Critical Mass
    UVA, 900 Brick Wall Patterns
    UVA, 11000 Bee
    UVA, 10079 Pizza Cutting
    C++ 向量<vector>的学习
    jenkins入门
  • 原文地址:https://www.cnblogs.com/-wyl/p/7640835.html
Copyright © 2011-2022 走看看