您的位置:首页 > 其它

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: