简体   繁体   中英

Form in jsp returns the text in the windows-1252

All the data on the page are displayed correctly. Text, to get out of the database, including. But when the form is submitted, the controller comes in text windows- 1252.

In jsp encoding specified.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

For form too.

<form:form method="POST" action="/event" modelAttribute="message" acceptCharset="UTF-8">

Filter in web.xml

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

What could be the problem?

This problem occurs if CharacterEncodingFilter is not first. In my case it was to blame spring security . After all configuration moved from java config to xml and set CharacterEncodingFilter before filter spring security , data started coming in the correct encoding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM