例如你要控制对root目录下文件的访问:首先更改$tomcat_home/root/web-inf/web.xml
1.在<web-app>和</web-app>之间加入
<security-constraint>
<web-resource-collection>
<web-resource-name>entire application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- note: this role is not present in the default users file -->
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<!-- define the login configuration for this application -->
<login-config>
<auth-method>basic</auth-method>
<realm-name>test access control</realm-name>
</login-config>
2.然后在$tomcat_home/conf/tomcat-users.xml中加入
<user name="user" password="password" roles="user"/>
roles的名字和web.xml中的相对应
在tomcat4.03中测试通过
闽公网安备 35060202000074号