Posted on 2009-04-09 14:46
ZhouFeng 閱讀(2168)
評論(1) 編輯 收藏 所屬分類:
原創 、
Web服務器
在Tomcat安裝目錄下的conf/web.xml最后的</web-app>之前增加如下代碼
<error-page>
<error-code>404</error-code>
<location>/web404.jsp</location>
</error-page>
也可以在應用的WEB-INF/web.xml下加入上述代碼
然后建立web404.jsp自定義的頁面,在頁面里顯示提示信息3秒后轉到起始頁面,我寫的頁面代碼如下
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="3;url=<%=basePath%>">
<title>資源錯誤</title>
</head>
<body>
<div align="center"><h1><font color="#800000">對不起,你所訪問的頁面不存在</font></h1></div>
</body>
</html>
經測試,訪問一個不存在的頁面,則轉到自定義的頁面,3秒后轉到起始頁,只要自定義頁面能夠被訪問,那么是否進行跳轉或是要進行其它什么操作就由你自己決定了