Encoding issue in JSP / Tomcat5

I have a web application running on Tomcat5. There are some flags on the jsp say page1.jsp page in which some French characters have a title and meaning (Français). When I select some checkboxes and submit the page, it will go to page2.jsp, where I show the selected headers. The problem is that special characters appear on this page (Franzais). This happens when the form method is "POST". In the case of "GET" it works fine. In Tomcat server.xml uriEncoding is defined as "UTF-8". I went through so many messages, but the problem remains.

+3
source share
3 answers

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

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

... and tell the container which encoding to use before reading any parameters, because the browser will not send the encoding used in the header:

request.setCharacterEncoding("UTF-8");

Finally, make sure that the encoding of the output page is specified both in the response header and in the meta tag in head.

+1
source

It looks like mixed encoding is being used. Make the following changes:

  • Make sure your <Connector>in server.xml has URIEncoding = "UTF-8". Just make this change and try GET. Well, if it breaks :)
  • Add the following to all your JSPs: <%@page pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
  • request.setCharacterEncoding("UTF-8") . , , , .
+1

You can see the answer here: UTF-8 and servlets on Tomcat / Linux

0
source

Source: https://habr.com/ru/post/1717221/


All Articles