I faced with strange issue. We have old application that was written and deployed on Tomcat 6. And now our security team said that Tomcat 6 is EOL and we need to migrate to new version of Tomcat.
I decided to migrate this application from version to version and with Tomcat 7 I faced with strange issue.
On UI we have many different html forms and some fields in this forms can be empty. With tomcat 6 such fields were interpreted as null values. After migration to tomcat 7 I receive empty string instead of null value.
After some googling I found that people suggest to specify such parameter in web.xml:
<context-param>
<param-name>org.apache.el.parser.COERCE_TO_ZERO</param-name>
<param-value>false</param-value>
</context-param>
And this does not helped
Also I want to mentioned that we also use Spring MVC in this app. But during migration I have not changed any version in code. The only thing I changed is version of tomcat
Update
I updated tomcat to latest available dockerized version(9.0.16-jre8). As a result I still have same issue.
Update 2
I do not have unlimited time for this ticket so I decided to manually update/replace all places where we check fields on null to start check on empty value.
Also I found that starting from version 7 tomcat uses relative path for redirect links and in 6 version Tomcat uses absolute links by default(or it was configured with some legacy field/property that was removed in 7 version).
If you want to enable logic for absolute path you need to specify useRelativeRedirects
attribute in Context configuration:
<Context useRelativeRedirects="false" />
Another point is that starting from Tomcat 8 it supports Rfc6265 and throw exception if your cookies have invalid format(in our case we have cookies that starts with .
). Right now Tomcat supports legacy cookie processor but it can be removed in future versions. To enable legacy cookie processor you need to add such line in Context configuration:
<Context useRelativeRedirects="false">
<CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
</Context>
Next thing also related to some new specifications is format of URLs and query parameters. In case you query params have some special characters you request will fail with new versions of Tomcat and in logs you will just see null
instead of request url. To fix this you need to add elaxedQueryChars
attribute for Connector
in server.xml like this:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443"
elaxedQueryChars="<>[\]^'{|}"/>
<>[\]^'{|}
== <>[\]'{|}
And last thing that I found is that some listeners that was used in Tomcat6 were removed in Tomcat7+. For example I removed such lines from server.xml:
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.core.JasperListener" />
One more thing. In new versions of Tomcat we have large list of jars specified in tomcat.util.scan.StandardJarScanFilter.jarsToSkip
. With default list jstl
library stop to work cause it is skipped by default. So you need to remove lines related to jstl
: