---
title: "jsp自定义错误页"
author: "gnnan"
date: "2011-09-08T11:39:54Z"
tags: []
categories: ["编程语言"]
slug: "jsp"
draft: false
lastmod: "2011-09-08T11:40:17Z"
id: 1168349
url: "https://gnnan.iteye.com/blog/1168349"
---

为了给浏览者一个友好的错误提示页面，我们可以自定义错误页面:  
步骤如下：  
一、打开WEB-INF 文件夹下web.xml 文件；  
二、在里面新增：  
&lt;!-- 404 页面不存在错误 --&gt;  
&lt;error-page&gt;  
   &lt;error-code&gt;404&lt;/error-code&gt;  
   &lt;location&gt;/errorpage404.htm&lt;/location&gt;  
&lt;/error-page&gt;  
&lt;!-- 500 服务器内部错误 --&gt;  
&lt;error-page&gt;  
   &lt;error-code&gt;500&lt;/error-code&gt;  
   &lt;location&gt;/errorpage500.htm&lt;/location&gt;  
&lt;/error-page&gt;  
&lt;!-- java.lang.Exception 异常错误, 依据这个标记可定义多个类似错误提示 --&gt;  
&lt;error-page&gt;  
   &lt;exception-type&gt;java.lang.Exception&lt;/exception-type&gt;  
   &lt;location&gt;/exception.htm&lt;/location&gt;  
&lt;/error-page&gt;  
三、保存web.xml 文件，重启应用服务器。