Spring MVC and UTF-8

Asked

Viewed 1,156 times

0

I’m making use of Spring MVC in a project, running on a Glassfish server and having trouble displaying text on JSP pages that contain special characters such as accents. I tried to put the charset in the HTML pages via HTML, HTML5 and even via JSP tag, but it didn’t help. My connection to the bank is confirmed using UTF-8 and I don’t know what else is missing.

2 answers

0


Confirm that you are using charset in HTML correctly:

HTML 4

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

HTML 5

<meta charset="utf-8"/>

JSP

<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page language="java" pageEncoding="UTF-8"%> 

Since you are using Spring MVC, it is important to register a filter that encoding to UTF-8. So, register it in your file web.xml the CharacterEncodingFilter and configure it to work with UTF-8.

<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> 

0

Take a look at the Glassfish configuration as well, to see if there is ok, in glassfish-web.xml, see if there is also UTF-8:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <jsp-config>
    </jsp-config>
    <parameter-encoding default-charset="UTF-8" />
</glassfish-web-app>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.