Empty page instead of custom tomcat error page
Asked Answered
G

7

7

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?

Gallop answered 4/10, 2010 at 14:23 Comment(0)
G
1

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.

Gallop answered 17/1, 2011 at 13:50 Comment(0)
S
2

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 
Swim answered 28/11, 2012 at 21:20 Comment(0)
G
1

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.

Gallop answered 17/1, 2011 at 13:50 Comment(0)
P
0

Note: You need to be sure that the page you specify does not begin with a number (i.e.: 404.jsp). This because, according to Java Syntax, you cannot start a class name with a number.

http://www.jguru.com/faq/view.jsp?EID=492774

Hope that helps :-)

Pacien answered 7/1, 2011 at 11:13 Comment(1)
for 404.jsp a _404_jsp.java is generated which compiles to _404_jsp.class which is invoked without trouble, so this can't be the reasonGallop
G
0

If it works fine when loading 404.jsp, and shows a blank page when tomcat actually tries to use the page to handle a 404 error, it could mean that there is an error in 404.jsp's source code that's only triggered by using the errorData object.

Check the logs. I was having a similar blank page problem and it turned out that I had an incorrect taglib URL.

EDIT

Also, JkMount should not be necessary since tomcat is already generating these 404s (i.e. they are not in Apache's purview).

Gerfen answered 14/1, 2011 at 23:44 Comment(0)
R
0

I had this problem as well, and it turns out the culprit was that I'd typed the name of the application context root into the error page location. That is,

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

Whereas it should of course have been

<error-page>
 <error-code>404</error-code>
 <location>/404.jsp</location>
</error-page>
Ramon answered 20/1, 2011 at 15:22 Comment(1)
as i answered myself some days ago: the location is appended to the webapps' path, so when a 404 occurs in the webapp with path /foo then /foo/{location} is served, so it seems one can't specify "global" error pagesGallop
W
0

I have faced this issue while running a static web project.I have done the following implementation, and it has worked for me.

Added the following lines in %CATALINA_HOME%/conf/web.xml

    <error-page> 
    <error-code>404</error-code>
    <location>/error_404.html</location>
    </error-page>
Woven answered 28/4, 2014 at 12:32 Comment(0)
F
-1

Its shows exactly 404 page not found or else? Because some other error codes also avail like 400,401,403,500. Have a look at this link for this http://docs.yahoo.com/docs/writeus/error.html

If you have any other add that error codes aslo in web.xml file. Hopes this helps. Happy coding...

Footle answered 2/12, 2010 at 7:11 Comment(1)
? you must have misunderstood my problemGallop

© 2022 - 2024 — McMap. All rights reserved.