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

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

问题描述

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

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).

但是,当我转到fubar dot com:8080/xyzzy时,JBoss显示了默认的404页面,其中显示了它是JBoss以及哪个JBoss版本.

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.

请告知.

推荐答案

如果要为JBoss 7中所有其他上下文自定义错误页面,这是Myapp应用程序中配置的一部分,那么您还将有:

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:

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

其中的web.xml文件是:

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>

然后在jboss-web.xml中将上下文根定义为'/',因此它将是:

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

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

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

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).

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

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.

希望对您有帮助!

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

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