2

I'm getting input from a text input field on a JSP page, that can contain Umlaute. (e.g. Ä,Ö,Ü,ä,ö,ü,ß).

Processing the input works fine for non-Umlaute. But whenever an Umlaut is entered in the Input field an incorrect value gets passed on.

For example:

  • If an "ä" (UTF-8:U+00E4) gets entered in the input field,
  • the String that is extracted from the argument is "ä" (UTF-8: U+00C3 and U+00A4)

It seems to me as if the UTF-8 hex encoding (which is c3 a4 for an "ä") gets used for the conversion.

How can I retrieve the correct value?


Here are snippets from the current implementation:

The JSP-page passes the input value "pk" on to the processing logic:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
...
<input type="text" name="<%=pk.toString()%>" value="<%=value%>" size="70"/>
<button type="submit" title="Edit" value='Save' onclick="action.value='doSave';pk.value='<%=pk.toString()%>'"><img src="icons/run.png"/>Save</button>

The value gets retrieved from args and converted to a string:

UUID pk = UUID.fromString(args.get("pk")); //$NON-NLS-1$
String value = args.get(pk.toString());

Note: Umlaute that are saved in the Database get displayed correctly on the page.

Kaadzia
  • 1,393
  • 1
  • 14
  • 34

1 Answers1

5

Note: Umlaute that are saved in the Database get displayed correctly on the page.

Due to this fact, I'll assume that you've already properly set the response encoding to UTF-8 by either <%@page pageEncoding="UTF-8"%> in JSP or by <jsp-config> in web.xml.

Left behind the request encoding. You wasn't clear in your question nor the code if you're using GET or POST. If you're using POST, then you'd need to create a servlet filter which explicitly sets the HTTP request body encoding:

request.setCharacterEncoding("UTF-8");

Or if you're using GET, then you'd need to dig in the server configuration to set the URI/parameter encoding to UTF-8. How to do that depends on the server used which is also not clear from the question, let alone from your question history. I'll therefore just give an example of Tomcat: set the URIEncoding attribute of the <Connector> element in Tomcat's /conf/server.xml:

<Connector ... URIEncoding="UTF-8">

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC, we're using post and setting the encoding in the request was indeed what was missing. – Kaadzia Nov 09 '12 at 07:57