Post Spring窗体和控制器UTF-8编码错误
我的UTF-8编码有问题。我的webapp使用法语单词,这些单词在我的jsp中正确显示,但在发布后不会显示在我的控制器中。 例如,在我的jsp中,我有: 门牌 当我发布表单时,控制器会得到: Pré名称 characterEncodingFilter是文件中的第一个筛选器,如中所述 这是我的jsp:Post Spring窗体和控制器UTF-8编码错误,post,spring-mvc,utf-8,character-encoding,hdiv,Post,Spring Mvc,Utf 8,Character Encoding,Hdiv,我的UTF-8编码有问题。我的webapp使用法语单词,这些单词在我的jsp中正确显示,但在发布后不会显示在我的控制器中。 例如,在我的jsp中,我有: 门牌 当我发布表单时,控制器会得到: Pré名称 characterEncodingFilter是文件中的第一个筛选器,如中所述 这是我的jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!doctype html>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="content-language" content="fr">
...
</head>
<form:form class="form-horizontal" modelAttribute="AlimentationForm"
action="${actionUrl}" method="POST">
...
<form:input path="questions" class='input-xlarge' type='text' value='Prénom de mon père'/>
</form>
...
...
My 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>/web/*</url-pattern>
</filter-mapping>
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
字符编码滤波器
/网/*
还有我的application-config.xml
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename">
<beans:value>classpath:messages</beans:value>
</beans:property>
<beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>
类路径:消息
我不知道我的应用程序或配置有什么问题,你知道吗
先谢谢你
编辑:我正在使用HDIV框架确保JSP页面正确编码发送到服务器的数据。尝试添加
<%@page pageEncoding="UTF-8" %>
添加到JSP的顶部,因为这样可以确保沿http发送的任何数据都能正确编码
我相信默认的http编码是ISO-8859-1。这个问题实际上来自HDIV框架版本2.1.2。如果无法使用下一版本,则可以使用修补程序
希望它能帮助别人。在jsp上添加“”怎么样?完成了,但我没有提到它。我已经编辑了我的帖子。这一行已经在我的jsp文件中了。如何更改post上的默认http编码?在您编辑它之前不是这样的!通常,对于普通表单,您可以使用springforms标记执行类似于not sure的操作。