Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character encoding in tomcat

I have a problem with encoding in Tomcat 6.0. On all jsp pages I've specified

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

and pageEncoding="UTF-8" in page directive. But when I pass parametres(cyrillic letters) by get or post methods I have another symbols that I have entered. I've read that to fix this issue in post methods i have to set request.setCharacterEncoding("UTF-8"); And it's really helps me. Also I've read that to fix it in get methods I have to specify URIEncoding="UTF-8" in Connector element in server.xml. And it also really works for get methods, but only if I don't specify request.setCharacterEncoding("UTF-8");. So, if I specify both of them, only post method's parameter passing works well. How can I do that also with get method?

edit when i'm using form to pass the parameters through GET methods URIEncoding in server.xml works. But if I use response.senRedirect()(which is also using GET method) method in servlet it modifies cyrillic parametres with another symbols

solved The problem was solved using java.net.URLEncoder. Every parameter has to be encoded by URLEncoder.encode(par, "UTF-8"). Then it will be displayed correctly.

like image 960
maks Avatar asked May 06 '26 21:05

maks


1 Answers

I resolved this issue by adding URIEncoder=UTF-8 in both http and ajp connector of tomcat server.xml. Did nothing other than this. I am using Spring, apache/tomcat.

like image 96
Vishwa Avatar answered May 10 '26 07:05

Vishwa