I already created a custom 404 page inside my web app deployed in JBoss AS 7.1. So if my app is at fubar dot com :8080/Myapp and I go to fubar dot com :8080/Myapp/xyzzy, I get the custom error page (defined in the web app's web.xml file).
However, when I go to fubar dot com :8080/xyzzy, JBoss displays the default 404 page which discloses that it's JBoss and which JBoss version.
I need to replace this page in order to hide this information.
Please advise.
If you want to customize the error pages for all the other contexts in JBoss 7, a part of the configuration you have in your Myapp application, you'll also have:
error.war | |- META-INF |- WEB-INF | | | |- web.xml | |- jboss-web.xml | |- error |- 404.html
where The web.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>yourcompanyname</display-name>
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
</web-app>
And in the jboss-web.xml define the context-root as '/', so it would be:
<jboss-web>
<context-root>/</context-root>
</jboss-web>
The file 404.html is your customized html error page that Jboss will show instead of the 404 default error. That's all, deploy this application in JBoss 7, and you'll have your custom 404 error page when you'll visit fubar dot com:8080/yzyqqa or whatever other root context. Remember that you'll have to keep the error configuration in your Myapp web.xml as well (and in all the other applications you may the deploy in the server).
By the way, have you considered making your app Myapp accessible directly from fubar dot com:8080? Or even better, making the jboss server only accessible from a proxy (for example Apache)?.This way you'd avoid this problem as well.
I hope it helps!
Your problem : You defined the custom error page in web.xml
of Myapp
. Now if you access any resource with root as Myapp
and the request throws a 404
it returns the custom error page.
Now you want that if you access any other root , here xxyzzzz
you want to return the custom error page.
Now logically, if you configured a file for other project you cant expect it to be same for other project
Unless
either you configure the same thing for other project , i.e. xxxyzzz
as well. i.e. place the 404 config in its web.xml
aswell.
or you need to do something at the server scope.
the 1st solution is fairly simple and easy in case there are less number of projects and you not expecting a URL that does not match any of the project.
if you want to go with 1st solution, you know how to do it
Regarding the 2nd approach. I could find some posts that should be helpful to you
refer these
with jboss as7, the custom of global web.xml is gone. I could find only one way to configure a global 404 error page. refer here. IT WORKS :D
Custom error pages in Apache for JBoss AS7
I believe you will have to create your own page. JBoss uses Tomcat for serving the web requests.
In Tomcat the way to define your own 404 response page is having the following snippet in your web.xml (Ref - http://wiki.apache.org/tomcat/FAQ/Miscellaneous#Q6)
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
A detailed page on how to do this with struts is created by mykong @ http://www.mkyong.com/struts/how-to-handle-404-error-in-struts/.
If you are using any other framework than struts you should have a equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With