views:

426

answers:

4

I have a web application running on Tomcat5. In a jsp page say page1.jsp, there are some check boxes, where title and value have some french characters (Français). When I select some of the check boxes and submit the page, it goes to page2.jsp where I am showing selected titles. Problem is, on this page the special characters are getting change (Français). This is happening when form's method is "POST". In case of "GET", it works fine. In Tomcat's server.xml, the uriEncoding is defined as "UTF-8". I have gone through so many posts but the problem is remain.

+1  A: 

I did a test. You need to add accept-charset to the form tag:

<form ... accept-charset="UTF-8" ...>

... and tell the container what encoding to use before reading any parameters, because the browser won't send the encoding it used in a header:

request.setCharacterEncoding("UTF-8");

Finally, make sure the encoding of the page you output is set in both the response header and a meta tag in the head.

Andrew Duffy
Doesn't seems to be working. On page1.jsp I have used -<form method='post' accept-charset="UTF-8" action='test2.jsp'> andrequest.setCharacterEncoding("UTF-8");On page2.jsp, I have used -response.setCharacterEncoding("UTF-8"); and<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">Am I somewhere wrong? Also, why problem goes off when using GET?
You need to call request.setCharacterEncoding("UTF-8") in the servlet or JSP that accepts the form - in this case, it's test2.jsp.
Andrew Duffy
Oh, I suspect that Tomcat uses UTF-8 by default when decoding URLs but something else (the system default?) for decoding POST bodies.
Andrew Duffy
+1  A: 

Looks like mixed encoding is used. Please make following changes,

  1. Make sure your <Connector> in server.xml have URIEncoding="UTF-8". Just make this change and try your GET. It's good if it breaks :)
  2. Add following to all your JSPs: <%@page pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
  3. Add request.setCharacterEncoding("UTF-8") to all your servlets. You might have to do this in a filter if you have other filters because this only has effect before parameters are processed.
ZZ Coder
A: 

Link I can recommend

LarsOn
A: 

You may want to take a look at the answer here: http://stackoverflow.com/questions/714339/utf-8-and-servlets-on-tomcat-linux

Mondain