服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

tomcat设置类似iis的访问密码

例如你要控制对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中测试通过 


扫描关注微信公众号