• web中的中文乱码处理


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

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


    2.ide编码设置为uTF-8

    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");

  • 相关阅读:
    BASIC-2 01字串
    BASIC-1 闰年判断
    BASIC-11 十六进制转十进制
    IO流之File类
    集合-下
    集合-上
    java常用类-下
    关于String的一些基础小题目
    java常用类-上
    异常
  • 原文地址:https://www.cnblogs.com/newAndHui/p/8136011.html
Copyright © 2020-2023  润新知