模块包括 ibm-web-bnd.xml 和 ibm-web-ext.xml 文件。发生错误 401、404 等时如何显示 Error.jsp 文件?
Module includes ibm-web-bnd.xml and ibm-web-ext.xml files. How do I show an Error.jsp file when error 401, 404 etc. happen?
我正在开发一个包含以下模块的应用程序
ibm-web-bnd.xml and ibm-web-ext.xml files
我正在尝试显示一个错误页面作为 CWE 345 的修复。
我试图将 ErrorPage 和 web.xml 添加到 WEB-INF 中,当发生错误时调用 ErrorPage.jsp
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<error-page>
<!-- Missing login -->
<error-code>401</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Forbidden directory listing -->
<error-code>403</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Unsupported servlet method -->
<error-code>503</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
</web-app>
这没有用。
我还尝试将上述代码添加到 ibm-web-bnd.xml 和 ibm-web-ext.xml 文件中。
我试过了
<application location="Parent.ear">
<web-ext moduleName="public" default-error-page="ErrorPage.jsp"/>
</application>
没有任何效果。
如有任何关于如何为上述模块显示错误页面的建议,我们将不胜感激。
更新:
我有但没有输入正确,它被代码片段忽略了。
从我的角度来看,看起来你做的一切都是正确的。唯一对我来说不正确的是你没有关闭 <web-app>
标签。尝试用 </web-app>
关闭标签
此外,请记住,您可以直接从 JSP 页面内部声明 JSP 页面错误页面。
<%@ page isErrorPage="true"%>
然后您可以使用此页面指令将您的用户转发到该页面:
<%@ page errorPage="error.jsp"%>
我得到了这个问题的解决方案。
模块中的 pom 文件忽略了 WEB-INF 文件夹中的所有内容。
我认为该模块根本没有被使用,但是当我删除它时应用程序无法运行。
解决方案是忽略 WEB-INF 中除 web.xml 文件之外的所有内容。
这解决了问题。
我正在开发一个包含以下模块的应用程序
ibm-web-bnd.xml and ibm-web-ext.xml files
我正在尝试显示一个错误页面作为 CWE 345 的修复。 我试图将 ErrorPage 和 web.xml 添加到 WEB-INF 中,当发生错误时调用 ErrorPage.jsp
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<error-page>
<!-- Missing login -->
<error-code>401</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Forbidden directory listing -->
<error-code>403</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
<error-page>
<!-- Unsupported servlet method -->
<error-code>503</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
</web-app>
这没有用。 我还尝试将上述代码添加到 ibm-web-bnd.xml 和 ibm-web-ext.xml 文件中。 我试过了
<application location="Parent.ear">
<web-ext moduleName="public" default-error-page="ErrorPage.jsp"/>
</application>
没有任何效果。
如有任何关于如何为上述模块显示错误页面的建议,我们将不胜感激。
更新: 我有但没有输入正确,它被代码片段忽略了。
从我的角度来看,看起来你做的一切都是正确的。唯一对我来说不正确的是你没有关闭 <web-app>
标签。尝试用 </web-app>
此外,请记住,您可以直接从 JSP 页面内部声明 JSP 页面错误页面。
<%@ page isErrorPage="true"%>
然后您可以使用此页面指令将您的用户转发到该页面:
<%@ page errorPage="error.jsp"%>
我得到了这个问题的解决方案。 模块中的 pom 文件忽略了 WEB-INF 文件夹中的所有内容。 我认为该模块根本没有被使用,但是当我删除它时应用程序无法运行。 解决方案是忽略 WEB-INF 中除 web.xml 文件之外的所有内容。 这解决了问题。