我可以为任何 HTTP 客户端错误代码 (4XX) 和 HTTP 服务器错误代码 (5XX) 定义 JSP 自定义错误页面吗?

发布于 2024-10-05 14:15:16 字数 307 浏览 0 评论 0原文

我正在使用 Jboss 服务器,我想知道它是否可以识别所有 HTTP 客户端错误代码(4XX)和 HTTP 服务器错误代码(5XX),以便我可以在 web.xml 中配置自定义错误页面,例如 502、503 等?提前致谢。

编辑:我没有找到任何定义此的文档。但@Jeremy 建议我一种测试它的方法: 编写一个 Servlet 以返回您想要的错误代码,如下所示。

response.sendError([Error code goes here],
  "Error Message");

I am using Jboss server, i want to know does it recognize all the HTTP Client Error Code(4XX) and HTTP Server Error Code(5XX) so that i can configure my custom error page like for 502, 503 etc. in web.xml? Thanks in advance.

Edit: i did't find any documentation that has defined this. but @Jeremy suggested me a way to test it out:
Write a Servlet to return error code you want as following.

response.sendError([Error code goes here],
  "Error Message");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拍不死你 2024-10-12 14:15:16

我想您正在寻找这个:

<error-page>
    <error-code>404</error-code>
    <location>/ErrorPage.jsp</location>
</error-page>

要测试这个,请编写一个专门返回错误代码的 servlet。

I think you are looking for this:

<error-page>
    <error-code>404</error-code>
    <location>/ErrorPage.jsp</location>
</error-page>

To test this, write a servlet that specifically returns the error code.

我也只是我 2024-10-12 14:15:16

设置自定义错误页面的方法很少。

  1. 如果您在表示层中使用 JSP。

    foo.jsp

    <%@页面errorPage="/errorPage.jsp" %> // 如果抛出任何异常,我们将重定向到 error.jsp
    

    errorPage.jsp

    <%@ page isErrorPage="true" %>
    

    我建议出于开发目的这样做。

  2. 在应用程序级别

    在 web.xml 中设置错误页面

    就像上面的答案

    <错误页面>;
        <错误代码>404
        <位置>/ErrorPage.jsp
    
    
  3. 我仍然需要通过编辑 jboss-web.sar 或 jboss-tomcatxx.sar 中找到的 web.xml 来尝试容器级别

There are few approaches to set custom error pages.

  1. If you are using JSP's in presentation layer.

    foo.jsp

    <%@ page errorPage="/errorPage.jsp" %> // Here we are redirecting to error.jsp if any exception is thrown
    

    errorPage.jsp

    <%@ page isErrorPage="true" %>
    

    I suggest this for development purposes.

  2. At Application Level

    Setting errorpages in web.xml

    like above answer

    <error-page>
        <error-code>404</error-code>
        <location>/ErrorPage.jsp</location>
    </error-page>
    
  3. I still need to experiment with Container level, by editing web.xml found in jboss-web.sar or jboss-tomcatxx.sar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文