简体   繁体   English

jsp中的表单返回Windows-1252中的文本

[英]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. 但是,当提交表单时,控制器进入文本窗口1252。

In jsp encoding specified. 在jsp编码中指定。

<%@ 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 过滤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. 如果不是第一个CharacterEncodingFilter,则会出现此问题。 In my case it was to blame spring security . 就我而言,这应该归咎于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. 在将所有配置从java config移至xml并在Filter spring security之前设置CharacterEncodingFilter之后,数据开始以正确的编码输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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