zoukankan      html  css  js  c++  java
  • SSM解决中文乱码

    一、tomcat配置

      配置tomcat时 设置utf-8编码,主要解决地址栏 url 中文乱码

    <!-- 配置tomcat -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <uriEncoding>utf-8</uriEncoding>
                        <useBodyEncodingForURI>true</useBodyEncodingForURI>
                    </configuration>
                </plugin>

    二、web.xml配置

      主要解决 request response 中文乱码

    <!--中文乱码-->
        <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>characterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    三、springmvc.xml配置

      主要解决request response请求前经过springmvc 导致中文乱码

    xmlns:mvc="http://www.springframework.org/schema/mvc"
    
    
     xsi:schemaLocation="http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd”
    
    
    
    <!-- springmvc @responseBoyd乱码及返回自定义对象 -->
        <mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/plain;charset=UTF-8</value>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                
                <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json</value>
                            <value>application/xml;charset=UTF-8</value>
                        </list>
                    </property>
                    <property name="features">
                        <array>
                            <!-- 下面配置,默认是false -->
                            <value>WriteMapNullValue</value>
                            <value>WriteNullNumberAsZero</value>
                            <value>WriteNullListAsEmpty</value>
                            <value>WriteNullStringAsEmpty</value>
                            <value>WriteNullBooleanAsFalse</value>
                            <value>WriteDateUseDateFormat</value>
                        </array>
                    </property>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
  • 相关阅读:
    Squid-Squid 多层Cache 如何设置实现墙内直连,墙外域名走国外Proxy
    利用win2008虚拟化hyper-v 和squid反向代理,自己做个IDC
    再次分享 pyspider 爬虫框架
    刘宇:我如何5分钟拿到李书福的投资?
    刘宇:2014年投资感悟
    刘宇(正和磁系资本创始人)_百度百科
    python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客
    采集爬虫中,解决网站限制IP的问题?
    Web 应用性能和压力测试工具 Gor
    dnspod-sr内网轻量级DNS首选方案
  • 原文地址:https://www.cnblogs.com/sloth-007/p/11136529.html
Copyright © 2011-2022 走看看