I'm learning Java, and while writing my first web app, I've encountered some problems with Polish letters (like ą, ć, ł, ś etc.). Problem is that when I bind the object to a form in GET
request, it shows ok in browser, with all Polish letters just fine (database is configured properly), but after hitting Send
button on the page in my controller, in POST
request, I get garbled text with Polish letters missing. When I set encoding in the view (JSP file) to utf-8
in controller instead of 'ą'
I get 'Ä'
(two bytes) and with encoding set to iso8895-2
I get '±'
(1 byte). With servlets the solution was to add
request.setCharacterEncoding("8859_2");
as the first line in POST
request, but Hibernate doesn't use HttpServletRequest
, so even when I add it, I still get garbage. STS (my IDE) is set to UTF-8
.
Is there any solution to his?
Browser log:
Request URL:http://localhost:8080/Project/register
Request Method:POST
Status Code:200
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Content-Language:pl-PL
Content-Length:3338
Content-Type:text/html;charset=UTF-8
Date:Mon, 29 Jan 2018 11:30:04 GMT
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:58
Content-Type:application/x-www-form-urlencoded
Cookie:JSESSIONID=88145A5FCBBD13FDBE3C288110B38187
DNT:1
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/Project/register
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.102 Safari/537.36 Vivaldi/1.94.971.8
Form Data
view source
view URL encoded
username:ąąą
email:
age:0
phone:0
password:
And after clicking view URL encoded:
%C4%85%C4%85%C4%85
Problem was solved by setting up filter and reconfiguring Tomcat a bit, described here: https://stackoverflow.com/a/40484064/8783698