Home > database >  How to use static error page through ErrorReportValve in Tomcat 8.5.75, running on Elastic Beanstalk
How to use static error page through ErrorReportValve in Tomcat 8.5.75, running on Elastic Beanstalk

Time:09-03

I have set up an ErrorReportValve in the Host section in Server.xml:

<Valve className="org.apache.catalina.valves.ErrorReportValve"
                errorCode.400="webapps/ROOT/error.html"
                showReport="false"
                showServerInfo="false" />

The Tomcat docs for errorCode.nnn state:

The location of the UTF-8 encoded HTML file to return for the HTTP error code represented by nnn. For example, errorCode.404 specifies the file to return for an HTTP 404 error. The location may be relative or absolule. If relative, it must be relative to $CATALINA_BASE. The special value of errorCode.0 may be used to define a default error page to be used if no error page is defined for a status code. If no matching error page is found, the default Error Report Valve response will be returned.

My $CATALINA_BASE is pointing to /usr/share/tomcat8 and my error page is found relative to this at webapps/ROOT/error.html:

# ls -lrt /usr/share/tomcat8/webapps/ROOT/error.html
-rw-r--r-- 1 tomcat tomcat 2934 Aug 31 18:24 /usr/share/tomcat8/webapps/ROOT/error.html

I can see the ErrorReportValve take effect by fiddling with the showReport and showServerInfo values but I cannot figure out how to reference the errorCode.nnn, having tried numerous combinations of static and relative paths.

I can get this to work perfectly well in Eclipse running a dynamic web project, but the relative path in Eclipse is wtpwebapps/myProject/error.html which isn't relevant in Elastic Beanstalk / Amazon Linux. I can also get 404 / 500 errors to work, although these are currently defined in an older way in web.xml, and so the relative path is different.

Has anyone been able to get a static error page for 400 errors in Amazon Linux / Tomcat?

CodePudding user response:

Tomcat 8.5.75 doesn't support this feature, please use 8.5.78 or above.

  • Related