在工程的web.xml中可以设置自定义错误页面,设置如下:
Xml代码
Xml代码
<error-page>
<error-code>404</error-code>
<location>/pagenotfound.jsp</location>
</error-page>
自定义的页面内容如下:
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<h3>访问的页面不见了
</h3>
这个页面发生了错误。<br/>
<br/>
您现在可以:<br/>
(1) 点击浏览器上的 "返回" 按钮并尝试通过其他方式进入我们的页面, 或者 <br/>
(2) 点击下方的链接转跳到网站的首页.<br/>
<br/>
<div class="linkTextA">
<a href="<%=basePath%>">跳转到首页</a>
</div>