{"id":375,"date":"2016-04-02T13:02:40","date_gmt":"2016-04-02T11:02:40","guid":{"rendered":"http:\/\/h2916922.stratoserver.net:8084\/?p=375"},"modified":"2016-09-08T13:14:57","modified_gmt":"2016-09-08T11:14:57","slug":"java-ee-request-params-re-encoding-to-utf-8","status":"publish","type":"post","link":"https:\/\/www.ivojonker.nl\/?p=375","title":{"rendered":"Java EE request params, re-encoding to UTF-8"},"content":{"rendered":"<p>Just a quick write as i encounter a lot of web applications where the front-end is using UTF-8 encoding to post values to the backend, while the backend, is interpreting them with different (java default iso-8859-1).<\/p>\n<p>Now since Servlet 2.3, there is the Request.setCharacterEncoding(), but unfortunately this doesn&#8217;t work if any single parameter has been read before setting the character encoding. In that case, you might do the following:<\/p>\n<pre class=\"lang:java decode:true\">String someText = request.getParameter(\"someText\");\r\nsomeText = new String(jsCaseProps.getBytes(Charset.defaultCharset()),request.getCharacterEncoding())<\/pre>\n<p>Where Charset.defaultCharset() is probably the\u00a0ISO-8859-1, as it is default for most application servers.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just a quick write as i encounter a lot of web applications where the front-end is using UTF-8 encoding to post values to the backend, while the backend, is interpreting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-geen-categorie"],"_links":{"self":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=375"}],"version-history":[{"count":5,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":460,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions\/460"}],"wp:attachment":[{"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ivojonker.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}