web项目配置404页面和500页面
2016-05-03 15:11
441 查看
一个项目里面拥有一个404页面和500页面是标配,接下来介绍一下怎样在你的项目里配置
1:分别切好一个404和500的页面,网上有许多这样的比较好看的页面
2:在web.xml里面配置
<!-- 404页面 -->
<error-page>
<error-code>404</error-code>
<location>/front/front_404.jsp</location>(里面写你的页面所存放的路径)
</error-page>
<!-- 500页面 -->
<error-page>
<error-code>500</error-code>
<location>/front/front_500.jsp</location>
</error-page>
3;在你的404或500页面加上下面两句isErrorPage="true"和<%response.setStatus(HttpServletResponse.SC_OK);%>
例子:<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<%response.setStatus(HttpServletResponse.SC_OK);%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="../pages/common/master.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${ctx}/resources/css/style.css" type="text/css" />
<title>404</title>
</head>
<body style="background:none;">
<div class="ds_center">
<img src="${ctx}/resources/images/404_r1_c1.png" />
抱歉,您访问的页面已经迷失了!<br />
<a href="${ctx}/userInfo/front_login.htm">返回登录页</a> <a href="javascript:history.go(-1);" style="margin-left:50px;">返回上一层</a>
</div>
</body>
</html>
1:分别切好一个404和500的页面,网上有许多这样的比较好看的页面
2:在web.xml里面配置
<!-- 404页面 -->
<error-page>
<error-code>404</error-code>
<location>/front/front_404.jsp</location>(里面写你的页面所存放的路径)
</error-page>
<!-- 500页面 -->
<error-page>
<error-code>500</error-code>
<location>/front/front_500.jsp</location>
</error-page>
3;在你的404或500页面加上下面两句isErrorPage="true"和<%response.setStatus(HttpServletResponse.SC_OK);%>
例子:<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<%response.setStatus(HttpServletResponse.SC_OK);%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="../pages/common/master.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${ctx}/resources/css/style.css" type="text/css" />
<title>404</title>
</head>
<body style="background:none;">
<div class="ds_center">
<img src="${ctx}/resources/images/404_r1_c1.png" />
抱歉,您访问的页面已经迷失了!<br />
<a href="${ctx}/userInfo/front_login.htm">返回登录页</a> <a href="javascript:history.go(-1);" style="margin-left:50px;">返回上一层</a>
</div>
</body>
</html>
相关文章推荐
- Android自定义View
- 含有蓝牙功能的App上线AppStore被拒的原因
- Android通过反射获取build.prop中key对应的value
- SDWebImage使用方法
- 用因果图分析微博经验值规则生成测试用例
- javapackager打包本地程序为.exe运行文件
- javascript
- opencv检测人脸并将检测到的人脸图像保存
- linux 系统无法启动的基本解决方法
- 第十/十一周训练1-3
- 第十/十一周训练1-2
- MongoDB数据库设计中6条重要的经验法则,part 1
- 二维数组的赋值
- appStore上传审核遭拒原因
- IOS开发中长按的手势事件编程
- Android总结 - ImageView
- 带头结点单链表的建立
- 第十/十一周训练1-1
- 提升方法 - 2 - 前向分布算法和提升树
- 初创公司DataStax:专注于Cassandra