web项目配置404页面和500页面

一个项目里面拥有一个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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值