如何创建自己的error404 jsp页面 [英] How do I create own error404 jsp page

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

问题描述

当用户用户在jsp页面中输入无效的url路径

时,我想创建自己的自定义error404。



web.xml

I want to create my own custom error404 when the user user enters invalid url path
in jsp page.

web.xml

<xml version="1.0" encoding="ISO-8859-1" ?>
	<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true">
		<display-name>Kastamandap </display-name>
		<error-page>
			<error-code>404</error-code>
			<location>/404Errorpage.jsp</location>
		</error-page>

	</web-app>





error404page.jsp





error404page.jsp

<%@ page isErrorPage="true" import="java.io.*" contentType="text/plain"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<H1>ERROR 404</H1>
StackTrace:
<%
	StringWriter stringWriter = new StringWriter();
	PrintWriter printWriter = new PrintWriter(stringWriter);
	exception.printStackTrace(printWriter);
	out.println(stringWriter);
	printWriter.close();
	stringWriter.close();
%>

</body>
</html>





我尝试过:



我已创建,但tomcat没有重定向到error404page.jsp.how我是否将此页面实现到所有其他jsp页面



What I have tried:

I have created but the tomcat is not redirecting to the error404page.jsp.how do I implement this page to all other jsp page

推荐答案

您的配置和文件系统之间的文件名不同。

在尝试检索404.jsp时收到404的讽刺
Your file names are different between your config and the file system.
The irony of receiving a 404 when trying to retrieve the 404.jsp
<location>/  404Errorpage.jsp     </location>
             error404page.jsp


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

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