Spring MVC and UTF-8

0

I'm making use of Spring MVC in a project, running on Glassfish server and having trouble displaying text on JSP pages that contain special characters like accents. I have already tried to put the charset in HTML pages via HTML, HTML5 and even via JSP tag, but it did not work. My connection to the bank is confirmedly using UTF-8 and I do not know what's missing.

    
asked by anonymous 23.05.2017 / 19:46

2 answers

0

Please 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 UTF-8. Then, register in your file web.xml o 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> 
    
23.05.2017 / 19:46
0

Take a look at the GlassFish configuration as well, to see if it's ok there, in glassfish-web.xml, see if it's also there with 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>
    
23.05.2017 / 20:26