[Spring MVC]フォームのPOSTデータ文字化けを解決する方法

2021年6月17日

1.JSP画面pageEncodingを指定
<%@ page language="java" contentType="text/html; charset=utf-8″ pageEncoding="utf-8″%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8″ />

2.tomcatサーバ設定
server.xml
<Connector URIEncoding="UTF-8″ connectionTimeout="20000″ port="8080″ protocol="HTTP/1.1″ redirectPort="8443″ useBodyEncodingForURI="true"/>

3.web.xmlにencodingを指定

<filter>
        <filter-name>CharacterEncoding</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>CharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

SpringMVC

Posted by arkgame