tomcat配置400/404/500类型的错误页面,修改项目默认路径,修改默认项目

修改项目默认路径,修改默认项目  http://xxx.xxxxxx.xxx  直接访问

找到tomcat路径中conf文件夹下server.xml文件找到

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

修改成

<Host name="localhost" appBase="/xxx/xxx/xxx/xxx/webapps"
            unpackWARs="true" autoDeploy="true">
        <Context docBase="/xxx/xxx/xxx/wxs_home" path="" debug="0" reloadable="true" crossContext="true"/>

说明:/xxx/xxx/xxx/xxx/webapps修改的项目默认路径  /xxx/xxx/xxx/wxs_home 修改的默认项目,放入自定义的首页index.jsp/index.html ;顺便放入错误提示页面error.jsp

错误提示页面:

error.jsp

<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>xxx错误</title>
</head>
<body>
	哎哟喂!您乘坐的这条“程序”违反了tomcat规则!请稍后访问......
</body>
</html>

找到tomcat路径中conf文件夹下web.xml文件找到

找到这段

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

在下面添加

<!-- 400错误 -->
	<error-page>
		<error-code>400</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- 404 页面不存在错误 -->
	<error-page>
		<error-code>404</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- 500 服务器内部错误 -->
	<error-page>
		<error-code>500</error-code>
		<location>/error.jsp</location>
	</error-page>
	<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/error.jsp</location>
	</error-page>
	<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
	<error-page>
		<exception-type>java.lang.NullPointerException</exception-type>
		<location>/error.jsp</location>
	</error-page>
 
	<error-page>
		<exception-type>javax.servlet.ServletException</exception-type>
		<location>/error.jsp</location>
	</error-page>

重启tomcat服务器,默认项目http://xxx.xxxxxx.xxx; 400/404/500类型的错误页面:http://xxx.xxxxxx.xxx/error.jsp

 

 

 

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tsxw001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值