Index

Enabling multipart files in servlet filter

${TOMCAT_HOME}/conf/context.xml
<Context allowCasualMultipartParsing="true">
enabling unbounded file size in ${TOMCAT_HOME}/conf/server.xml (tomcat >= 7.063)
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"  
               maxPostSize="-1"
               />

starting tomcat with system properties

opt/tomcat/bin/setenv.sh
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=dev"
workaround for tomcat startup hanging on entropy
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

configuring UTF-8

set default for connectors in server.xml
<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               maxPostSize="-1"
               redirectPort="8443" 
               URIEncoding="UTF-8"
/>
set encoding for requests and responses in servlet filter
req.setCharacterEncoding("UTF-8");
res.setCharacterEncoding("UTF-8");
generate UTF-8 content with content generation libraries, for example for freemarker:
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setEncoding(Locale.getDefault(), "UTF-8");
...
new OutputStreamWriter(response.getOutputStream(), Charset.forName("UTF-8"))
fix encoding issues on Ubuntu server VM's for java (console, javamail)
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Dfile.encoding=UTF-8 "


Tomcat FAQ on encoding:
https://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q8