I've a form with Primefaces. The header of the xml file looks like that:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
When I send the form, I take the values with HttpServletRequest
:
public String handleRequest(HttpServletRequest request) {
String shortname = request.getParameter("shortname");
(...)
Now when shortname
contains a umlaute, for example an ü, the umlaute will be saved as UTF-8 encoded. So my ü get saved as Ã1⁄4.
How can I decode it again? All the tutorials use a byte-array, but I haven't one.
I need this variable in a EMail, and it doesn't look really good with some hieroglyphics.
Michael Schmidt
asked Jul 10, 2013 at 13:57
1 Answer 1
You need to tell the HttpServletRequest
instance that it's in UTF-8:
public String handleRequest(HttpServletRequest request) {
try {
request.setCharacterEncoding("UTF-8");
String shortname = request.getParameter("shortname");
(...)
}
catch (UnsupportedEncodingException e) {
// ...
}
}
answered Jul 10, 2013 at 14:40
-
1Thanks again! BTW,
setCharacterEncoding
should be surrounded by try/catch :)Michael Schmidt– Michael Schmidt2013年07月10日 14:49:46 +00:00Commented Jul 10, 2013 at 14:49 -
Yeah you're right. Serves me right for not actually compiling first :)Seth Davenport– Seth Davenport2013年07月10日 14:54:15 +00:00Commented Jul 10, 2013 at 14:54
lang-java
request.setCharacterEncoding("UTF-8");
?