posts - 2, comments - 27, trackbacks - 0, articles - 60
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

在TOMCAT下自定义404错误页面

Posted on 2009-04-09 14:46 ZhouFeng 阅读(2154) 评论(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秒后转到起始页,只要自定义页面能够被访问,那么是否进行跳转或是要进行其它什么操作就由你自己决定了

评论

# re: 在TOMCAT下自定义404错误页面  回复  更多评论   

2011-10-31 14:36 by 1111111111
这样的话,会对seo有影响

只有注册用户登录后才能发表评论。


网站导航: