如何自定义 JBoss AS7 404 页面 [英] How to customize JBoss AS7 404 page

查看:34
本文介绍了如何自定义 JBoss AS7 404 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在部署在 JBoss AS 7.1 中的 Web 应用程序中创建了一个自定义 404 页面.因此,如果我的应用程序位于 fubar dot com :8080/Myapp 并且我转到 fubar dot com :8080/Myapp/xyzzy,我将获得自定义错误页面(在 Web 应用程序的 web.xml 文件中定义).

但是,当我访问 fubar dot com :8080/xyzzy 时,JBoss 会显示默认的 404 页面,该页面显示它是 JBoss 以及哪个 JBoss 版本.

我需要替换此页面以隐藏此信息.

请指教.

解决方案

如果您想为 JBoss 7 中的所有其他上下文(您在 Myapp 应用程序中的配置的一部分)自定义错误页面,您还需要有:

  • 禁用 JBoss 欢迎页面:在文件 standalone/configuration/standalone.xml(或 domain/configuration/domain.xml)中,将属性 enable-welcome-root 设置为 false(默认为 true)
  • 然后,您必须部署一个简单的 war 文件,将其上下文根设置为/",并为此战争定义错误页面(使用与 Myapp 相同的方法).因此,war 结构应该类似于(error.war 名称是任意的):
<块引用>

 error.war||- 元信息|- 网络信息||||- web.xml||- jboss-web.xml||- 错误|- 404.html

web.xml 文件在哪里:

<display-name>您的公司名称</display-name><错误页面><错误代码>404</错误代码><location>/error/404.html</location></错误页面></web-app>

在 jboss-web.xml 中将上下文根定义为/",所以它是:

<context-root>/</context-root></jboss-web>

文件 404.html 是 Jboss 将显示的自定义 html 错误页面,而不是 404 默认错误.就是这样,在 JBoss 7 中部署这个应用程序,当您访问 fubar dot com:8080/yzyqqa 或任何其他根上下文时,您将拥有自定义的 404 错误页面.请记住,您还必须在 Myapp web.xml 中保留错误配置(在所有其他应用程序中,您可能会在服务器中部署).

顺便说一下,您是否考虑过让您的应用 Myapp 可以直接从 fubar dot com:8080 访问?或者甚至更好,让 jboss 服务器只能从代理(例如 Apache)访问?.这样你也可以避免这个问题.

希望能帮到你!

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:

  • 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:

<?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!

这篇关于如何自定义 JBoss AS7 404 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆