南山不會落梅花 2023-05-17 15:54 采纳率: 0%
浏览 20

Tomcat如何限制可以访问的文件类型

在网上找了只知道如何限制某个目录下的所有文件都不能访问
如下:限制了webapps/testFile目录下的所有文件都不能访问
问题1:
我想知道只限制testFile目录下的.txt类型的文件怎么做?
问题2:
或者我想只允许testFile目录下的png文件可以访问,要怎么做?

<security-constraint>
          <display-name>Tomcat Server Configuration Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>testFile</web-resource-name>
            <url-pattern>/testFile/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
        </auth-constraint>
 </security-constraint>

  • 写回答

2条回答 默认 最新

  • 瞬间的未来式 2023-05-17 15:58
    关注

    该回答引用chatgpt:
    要限制testFile目录下的.txt类型的文件,你可以在 标签内添加一个 标签来指定要限制的文件类型。以下是修改后的示例代码:

    
    <security-constraint>
        <display-name>Tomcat Server Configuration Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>testFile</web-resource-name>
            <url-pattern>/testFile/*</url-pattern>
            <http-method>GET</http-method> <!-- 可选,只限制特定的HTTP方法 -->
            <mime-type>text/plain</mime-type> <!-- 只限制.txt类型的文件 -->
        </web-resource-collection>
        <auth-constraint>
        </auth-constraint>
    </security-constraint>
    
    
    <security-constraint>
        <display-name>Tomcat Server Configuration Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>testFile</web-resource-name>
            <url-pattern>/testFile/*</url-pattern>
            <http-method>GET</http-method> <!-- 可选,只限制特定的HTTP方法 -->
            <mime-type>image/png</mime-type> <!-- 只允许.png类型的文件 -->
        </web-resource-collection>
        <auth-constraint>
        </auth-constraint>
    </security-constraint>
    
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 5月17日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题