I'm currently learning JEE and within an exercise I just need to send text data from a .jsp file to another, using a basic form with a POST method. In this form, I want to be able to use accented characters, so I use <%@page pageEncoding="UTF-8" %>
on top of my jsp files, they also have both the <meta charset="utf-8">
tags and my IDE (Eclipse) is configurated to encode everything in UTF-8.
The problem is that at the end of the line, when I try to display my characters using EL, the accented characters (and the other ones I guess) are encoded in ISO-8859-1.
Which is really peculiar here is that when sending data using a GET method, I don't have any problem at all. Same result when I pass a String in the request via an attribute set in a servlet.
In fact I already solved the problem by sending the request to a servlet and calling request.setCharacterEncoding("utf-8")
in a doPost method (let's precise that calling request.getCharacterEncoding()
before that gives me null
), but I'd like to understand what exactly is happening here. I guess it comes from a server misconfiguration, but when I check the web.xml file of my server config I have these lines :
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
My confusion comes from the fact that nobody ever told me to use the request.setCharacterEncoding("utf-8")
, and that it does not appear normal to me that I would have to do so, so I guess the question would be : do I absolutely have to use it ? Why ? Shouldn't the encoding be handled by configuration of the server ?
I'm using Tomcat 9 for the server, and I'm under Ubuntu (don't know if it helps).