0

I use a small HTML form for a request to a tomcat server (servlet). If I use the "GET" request, my implemented "SetCharacterEncodingFilter" works very well and the result shows me all of the german "umlauts". But if I use a POST request (and unfortunately I need to do this), all of the "umlauts" look very funny ;-)

The HTML part looks like this:

<form id="form1" name="form1" method="POST" 
accept-charset="uft-8" 
action="http://localhost:8080/foo">
<p>
<label for="textfield"></label>
<textarea name="text" id="text" 
cols="45" rows="5"></textarea>
</p>
</form>

The Servlet part:

protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
throws ServletException, IOException, JSONException, Exception {

response.setContentType("text/html;charset=UTF-8");

String querytext = request.getParameter("text");

... 
...

Could anyone help?

Thanks in advance!

user32168
  • 45
  • 6

2 Answers2

0

Don't set the charset on the response. This has no effect on what the client is sending you. It will only affect what you send back to the client.

Instead try setting the charset on the request before getting the parameters:

request.setCharacterEncoding("UTF-8") // or ISO-8859-1, you have to check
String querytext = request.getParameter("text");

The charset you get depends on the HTTP header initially sent to the client, so browsers usually honor this and use the same charset for POST.

betomontejo
  • 1,657
  • 14
  • 26
0

For GET requests you need to set URIEncoding="UTF-8" on tomcat Connector tag in server.xml; for POST requests the charset filter should work, but it must be the first filter configured. see: http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q3

Nightingale7
  • 311
  • 2
  • 6