tomcat禁止访问路径与文件、错误页面跳转配置

tomcat禁止访问文件与文件目录

最近项目扫描的时候遇到一个问题,需要在tomcat中限制对包含项目信息文件的访问,在使用eclipse写项目是,会生成一个.project文件,这个文件里面包含了项目的关键信息,而且有时候删除扔能继续访问,于是只能对这个文件限制web访问,否则会存在安全漏洞,以下是解决办法:

在tomcat/conf/web.xml中加入以下代码

<security-constraint>
    <display-name>Forbidden</display-name>
    <web-resource-collection>
        <web-resource-name>aaa</web-resource-name><!--//填入要保护的项目名-->
            <url-pattern>/.project</url-pattern><!--//填入需要被限制的文件路径-->
    </web-resource-collection>
    <auth-constraint>
        <role-name/>
    </auth-constraint>
</security-constraint>

tomcat访问报错跳转

设置自定义的项目报错页面,同样在web.xml中添加:

<error-page>  
        <error-code>403</error-code>  
        <location>/error/authlimit.jsp</location>  
  </error-page>
  
  <error-page>  
        <error-code>404</error-code>  
        <location>/error/pagenotfound.jsp</location>  
  </error-page>
  
  <error-page>  
        <error-code>500</error-code>  
        <location>/error/servererror.jsp</location>  
  </error-page>

访问找不到页面 根据情况进行调整即可

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="org.jxstar.util.config.SystemVar,
				 org.jxstar.security.LicenseVar,
				 java.util.Map,
				 org.jxstar.util.factory.FactoryUtil,
				 org.jxstar.control.login.OneLoginUtil" %>
<%
	String contextpath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
  <head>
    <title>403</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	<style>
		body{
			 background-color:#1196EE;
		}
		img{
			width:300px;
		}
		.error-info{
			width:30%;
			margin:5% 35%;
			text-align:center;
		}
		.error-desc span{
			color:#eee;
			font-size:18px;
		}
	</style>

  </head>
  
  <body>
	  <div class="error-info">
    		<img src="<%=contextpath %>/resources/images/error/403.png" />
    		<div class="error-desc">
	    		<span>Sorry,您访问的页面不存在</span>
    		</div>
	  </div>
  </body>
</html>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值