Tomcat 下设置用用户名和密码访问文件目录

1、修改tomcat-user.xml

要想配置管理员用户名和密码,需要修改tomcat安装文件下的conf中的tomcat-user.xml文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<role rolename="role1"/>
<user username="lmmbao" password="LmmBao@2014" roles="role1"/>
</tomcat-users>

2、修改web.xml

修改工程目录下的web.xml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
   <security-constraint>
<web-resource-collection>
<display-name>Example</display-name>
<web-resource-name>My Test</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>My Test</realm-name>
</login-config>

3、重启动tomcat6

重启动tomcat6, 输入:http://127.0.0.1:8080/
输入用户名:admin, 密码admin。看到目录下文件的内容。
至此,tomcat管理员用户名和密码就配置好了。