web中的乱码处理

1 .web中的中文乱码处理

1.页面设置pageEncoding="UTF-8"

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>

2.ide编码设置为uTF-8

web中的乱码处理

3.tomcat中的 service.xml配置 URIEncoding="UTF-8"

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

4.web.xml添加过滤器

<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>

相当于servlet中的:

request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");

上一篇:一般处理程序,将nvarchar值转换成数据类型int时失败


下一篇:基于HTML5 Canvas WebGL制作分离摩托车