Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Customize 404 errors in Apache Tomcat

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One would think the answer to this question is all over the web. But honestly, I can't find any good answers.

I want to customize (or redirect) the 400-500 errors running on my apache tomcat server.

Oddly, the current 404 message is blank.. doesn't even say 404??

The source of the page is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>


I've edited the web.xml file here at the very bottom and restarted the server:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\web.xml

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

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

</web-app>

Do I need to move this file to somewhere else, like under the webapps directory?

Also, I placed the error404.jsp page isnide this directory:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\Catalina\localhost

So, I'm lost... thank you for your help.

John
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each application running under Tomcat will have it's own web.xml file (located under the WEB-INF directory.

The location entry will list the location of the JSP relative to the root of the application.

Example (assuming your app is named "MyApp"):
tomcat/webapps/MyApp
tomcat/webapps/MyApp/error404.jsp
tomcat/webapps/MyApp/WEB-INF/web.xml

When Tomcat starts up, it scans the webapps directory for war files or properly constructed directory structures and deploys them as web applications.
 
Ranch Hand
Posts: 62
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben Souther's answer worked for me. +1
 
Saloon Keeper
Posts: 23429
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Kat!

Tomcat has, in effect, a "shadow" webapp that lies underneath the actual webapps. It's where requests that cannot be processed using the logic that's in the webapp go.

The most obvious case is when you submit a URL that doesn't map to any of the servlets defined in a webapp's web.xml file. For example, a JSP or image request.

When the URL doesn't fit the app's URL pattern list, it gets sent to this "shadow" app's default servlet, which provides the default action - locating a compiled JSP (and, if necessary compiling it) and invoking its generated servlet code, or for non-code files and directories, copying/listing the contents of the file or directory whose resource location corresponds to the path provided in the URL.

If I tried, I could probably find a way to do what you're asking, but I don't recommend it. The default actions for Tomcat really shouldn't be customized, or the essential portability of web applications becomes compromised. Ideally, a J2EE/JEE web app is self-contained and will operate the same way on any copy of Tomcat in the world. And will require minimal changes to run on any other brand of J2EE/JEE-compliant web application server, such as JBoss.
 
Happily living in the valley of the dried frogs with a few tiny ads.
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic