user2130951 user2130951 - 4 months ago 28
HTML Question

Character encoding garbled characters in post JSF

I have the following document being posted in JSF.

<h:panelGrid columns="2">
<h:outputText value="Klubbnamn"></h:outputText>
<h:inputText name="clubname" value="#{}"></h:inputText>
<h:commandButton value="Spara" action="#{serviceHCP.saveClub(club) }"></h:commandButton>

writing åäö as the value for posting will render me åäö back. Everything written in the xhtml file will look like it should it's only the posted value that will be garbled. If I hard code it in the java class it will be correctly saved in the database. So I am sure there is something wrong with the post.

I have tried switching the webpage to is0-8859-1 without result. Tomcat is reporting default as utf-8.

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns=""><html xmlns=""><head><link type="text/css" rel="stylesheet" href="/BowlingFacelets/faces/javax.faces.resource/theme.css?ln=primefaces-aristo" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Default title</title>
<link rel="stylesheet" type="text/css" href="hcp-style.css" /></head>





This definitely looks like a problem with the request encoding. You should check the request character encoding header of the HTTP POST with FireBug or a tool like Wireshark.

In the request headers look for the Content-Type. It must contain: charset=utf-8

If this is not the case something in your setup is wrong because JSF should take care of the request character encoding.

Despite you can try to set the character encoding in a self-made filter. It could be something like this:

    public class CharEncodingFilter implements Filter {

        public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws ServletException, IOException {
            chain.doFilter(request, response);

See also:

Similar questions: