0
votes

I am running my application in WebSphere Liberty Profile. The URL to my application is as below:

http://myhostname:1234/Foo

I am able to customize the error page inside my war's web.xml when the user request any unknown page for e.g.

http://myhostname:1234/Foo/whatever_page

But I am not able to customize the 404 error before the user entering my Foo context root, for e.g.

http://myhostname:1234/whatever_here

I've seen some tutorial recommends to do this in Http Web Server, but unfortunately this is not an option for me. Also, I'm not able to use the root context (myhostname:1234/) for my application due to some reason.

Please advice how could I achieve this with only application server.

1

1 Answers

-1
votes

I am not sure if what you are looking to do, given your stated restrictions are possible. The context root is the entry point for that specific application, so you will not be able to specify anything in the web.xml since that is encapsulated within the application.

I was just looking at the response payload that liberty returns when you do an HTTP GET request to a bad context root, and my guess is that it is returning html generated somewhere in a Java file which leads me to believe this will not be overridable.

Your easiest option will probably be the two that you stated in your original post.

EDIT:

It appears tomcat has the functionality you seek:

http://davidghedini.blogspot.com/2010/10/tomcat-custom-404-page.html

I gave it a try and it works if you put in a bad context root. Tomcat has a ROOT folder, and because it is implemented this way, it is able to handle the case you are trying to cover. If you wanted to do this on liberty, you could make another .war with / as the context root and handle your 404 there as this is what apache does (basically mimicing what is in the ROOT folder of tomcat). The only difference is tomcat seems to provide this ROOT for you "out-of-the-box" while in liberty you'd need to generate it yourself.