Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty page instead of custom tomcat error page

My setting: Apache 2.2 + Tomcat 6.0 @ Windows 2008 R2 64bit

  • static webpages: /
  • servlet: /foo
  • tomcat and apache are connected by mod_jk
  • 404.jsp is placed in tomcat\webapps\ROOT

tomcat\conf\web.xml:

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>

apache\conf\extra\httpd-ssl.conf:

JkMount /foo/* worker1
JkMount /404.jsp worker1

When I open https://...../404.jsp my custom error page is displayed. But when I open https://...../foo/nonexisting.html an empty page is displayed.

If I remove the <error-page>...</error-page> code from web.xml and open https://...../foo/nonexisting.html then tomcats own 404 is displayed.

Any hints?

like image 380
Alexander Avatar asked Oct 04 '10 14:10

Alexander


People also ask

Where is the default error page in Tomcat?

The default Tomcat error page exposes the Tomcat version that SDM is using. After the above changes, when the SDM URL is accessed via http://<SD server hostname>:<port#>/abc, a screen similar to the following will appear that does not have the Tomcat version listed.

Why do you need custom error pages?

Custom error pages enable you to customize the pages that display when an error occurs. This makes your website appear more professional and also prevents visitors from leaving your site. If a visitor sees a generic error page, they are likely to leave your site.

How to get error message in JSP?

To create a JSP error page, we need to set page directive attribute isErrorPage value to true, then we can access exception jsp implicit object in the JSP and use it to send customized error message to the client.


2 Answers

The Jkmount should have the context as parameter, ex:

JkMount /mycontext/* worker1

then the pages are accessed this way:

https://mycontext/someservlet/

or

https://mycontext/foo/nonexisting.html 
like image 167
Leon Avatar answered Oct 27 '22 11:10

Leon


As far as i can see it, webapps' errors can't be handled with error pages placed in ROOT. I now put the 404.jsp in every webapp (/foo/404.jsp, /bar/404.jsp, ...) and now it works. I can safely delete the 404.jsp in ROOT, but if I delete the 404.jsp in /foo or /bar a blank page is served if a 404 occurres in either webapp. Either tomcat ignores the leading / in the "location" element or the content of this element is appended at the 'calling' webapp's path.

like image 1
Alexander Avatar answered Oct 27 '22 09:10

Alexander