MvcConfiguration
@Configuration
@ComponentScan(basePackages="com")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="nav-md">
<form:form method="POST" modelAttribute="fluxDomaine" class="form-horizontal form-label-left" >
<form:input type="hidden" path="id" id="id"/>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="INDCTR_DS">INDCTR DS </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<form:input type="text" path="INDCTR_DS" id="INDCTR_DS" name="INDCTR_DS" class="form-control col-md-7 col-xs-12"/>
</div>
<form:errors path="INDCTR_DS" cssClass="alerttt" />
</div>
<input type="submit" class="btn btn-success" value="Add"/>
</form:form>
</body>
</html>
i'm facing a problem with encoding , for example if i save a " à " it becomes " à " and " é " becomes " é ", and when i try to manually save it in my mysql DB its saving proprely.
Thanks for any advices..
I used to get this trouble while working with Spring MVC too.
Just followed this article: http://fazlansabar.blogspot.com/2012/06/how-to-enable-utf-8-support-on-tomcat.html and it's worked.
You need to define a SpringCharacterEncoding
filter . Simply add below lines to the web.xml
in your Spring MVC project .This will enforce UTF-8 encoding strictly in your code.
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Special characters issue, i replaced :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
by
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
and i was able to persist special characters as i want..
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.