How to customize JBoss AS7 404 page

后端 未结 3 936
难免孤独
难免孤独 2020-12-16 23:47

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

3条回答
  •  没有蜡笔的小新
    2020-12-17 00:32

    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:

    • to disable JBoss welcome page: in the file standalone/configuration/standalone.xml (or domain/configuration/domain.xml), set the attribute enable-welcome-root as false (by default it's true)
    • Then you'll have to deploy a simple war file setting its context-root to '/', and define the error page for this war (using the same method you've used for Myapp). So, the war structure should be similar to (the error.war name is arbitrary):
       error.war
        |
        |- META-INF
        |- WEB-INF
        |     |    
        |     |- web.xml
        |     |- jboss-web.xml
        |
        |- error
              |- 404.html
    

    where The web.xml file is:

    
    
      yourcompanyname
      
                404
                /error/404.html
      
    
    

    And in the jboss-web.xml define the context-root as '/', so it would be:

    
        /
    
    

    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!

提交回复
热议问题