伙计们我正在努力解决在Windows环境中在Tomcat中打开自定义错误页面的问题.我得到的一些解决方案但没有运气.我尝试了几乎所有的链接,但它不适合我.其中一些用于Tomcat中部署的其他解决方案,但不适用于我的Web服务
我的web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<location>/error.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
我从我的Servlet 3.0应用程序发送错误
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
我把我的error.html放在我的WebService的根目录中.
我为JSP页面而不是HTML获得的一些链接也是我尝试过的
在我使用JSP的情况下:
<%@ page isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Error</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
仅供参考,它适用于其他Tomcat内置解决方案,它运行良好.但是在我的Web服务中,我得到了响应500,但页面空白.另一件事我禁用了我的Internet Explorer 9.0显示错误友好页面仍然响应来自servlet 500.但是错误页面是空的.
如果对我的查询有任何想法或疑问,请告诉我.我尽快需要它.
我们在生产中有 tomcat 9 Web 服务器。我们面临的问题是,如果 tomcat 收到任何格式错误的 URL,我们希望为我们的应用程序显示自定义错误页面,如下所示
或者
我在tomcat应用服务器的web.xml中添加了error page标签如下
<error-page>
<error-code>400</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
我们在tomcat的webapps目录下的应用程序ROOT文件夹中有error.html。
每当用户尝试请求任何不存在的网页时,他都会收到与上面指定的 404 错误代码正确对应的错误页面。
真正的问题是当用户在浏览器中输入格式错误的 URL(如http://URL/|)时,tomcat 无法重定向到 error.html 。
Tomcat 显示的是默认的 400 bad request 错误页面,而不是自定义错误页面。