How can I change the default encoding of a tomcat server/container?

33,841

Solution 1

Add this to your catalina.sh script:

set JAVA_OPTS=-Djavax.servlet.request.encoding=Cp1252 -Dfile.encoding=Cp1252

Also in conf/server.xml you want to make this change so the URI encoding is set accordingly:

<Connector port="8080" URIEncoding="Cp1252"/>

Solution 2

If you use servlet filters you could add a call to response.setCharacterEncoding("Cp1252"); to all responses. If the response contains characters then your chosen encoding will be used.

response.setCharacterEncoding("Cp1252");

Please see https://tomcat.apache.org/tomcat-8.5-doc/servletapi/javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)

Share:
33,841

Related videos on Youtube

Dark Star1
Author by

Dark Star1

The true mind can weather all the lies and illusions without being lost. The true heart can toughen the poison of hatred without being harmed. Since beginning-less time, darkness thrives in the void, but always yields to purifying light.

Updated on September 17, 2022

Comments

  • Dark Star1
    Dark Star1 over 1 year

    I'm having problems with the character encoding of my webapp and would like to know how I can go about changing the default encoding of tomcat on the Linux production server to match the cp 1252 encoding of the dev server on windows (or at least experiment with different encoding until I can find the right one).

    Thanks