Posted on 2009-04-09 14:46
ZhouFeng 閱讀(2168)
評(píng)論(1) 編輯 收藏 所屬分類:
原創(chuàng) 、
Web服務(wù)器
在Tomcat安裝目錄下的conf/web.xml最后的</web-app>之前增加如下代碼
<error-page>
<error-code>404</error-code>
<location>/web404.jsp</location>
</error-page>
也可以在應(yīng)用的WEB-INF/web.xml下加入上述代碼
然后建立web404.jsp自定義的頁(yè)面,在頁(yè)面里顯示提示信息3秒后轉(zhuǎn)到起始頁(yè)面,我寫的頁(yè)面代碼如下
<%@ 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>資源錯(cuò)誤</title>
</head>
<body>
<div align="center"><h1><font color="#800000">對(duì)不起,你所訪問(wèn)的頁(yè)面不存在</font></h1></div>
</body>
</html>
經(jīng)測(cè)試,訪問(wèn)一個(gè)不存在的頁(yè)面,則轉(zhuǎn)到自定義的頁(yè)面,3秒后轉(zhuǎn)到起始頁(yè),只要自定義頁(yè)面能夠被訪問(wèn),那么是否進(jìn)行跳轉(zhuǎn)或是要進(jìn)行其它什么操作就由你自己決定了