安装完tomcat,或者解压完tomcat后,在tomcat的目录下有个conf文件夹,在这个文件夹下面有一个tomcat-
users.xml的文件,这个文件里面的配置信息是当我们进入http://localhost:8080 页面后,有些功能需要登录才能

进行访问。今天我解压好了一个tomcat,环境变量也配置好了,启动服务也没问题,就是登录不进去Manager App,大

概花了我一个下午的时间才解决这个问题。
  首先tomcat-users.xml这个文件就是tomcat提供给我们进行登录用户的配置,但是一开始我配置了很多次也不成功
,在网上也查了很多方法没用,接下来我将说明一下如何配置这个用户。
  1、首先你确定在conf目录下的server.xml文件有
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" 
factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" 
pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
这样一段代码,让tomcat启动服务后能加载到conf/tomcat-users.xml,这个文件。
  2、新解压的tomcat下的tomcat-users.xml,中的user全部都是被注释掉的
<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. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
</tomcat-users>
我们需要把那个注释去掉才能是的user生效,有很多人在这个地方犯错,注释不去掉,那都是没用的。
  3、注意在配置username的时候,不要取重复的名字,因为这样很可能让你的配置不起效果。
  4、使用tomcat7.X版本的朋友们注意了,这也是今天下午被坑的原因,tomcat7.X的user配置是有一定的规定的,

不能随意更改,你改成其他的很有可能不会生效,本人亲测,原来各种网上百度,找了很多种的配置方法就是没效果,

结果我将user配置改成如下结果终于登录进去了。
<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<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. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->

<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>

</tomcat-users>
  5、最后需要注意的是,修改了配置文件需要重新启动服务器,好让服务器重新加载修改后的配置文件。

[转]关于tomcat 中的 tomcat-users.xml 配置不生效原因的更多相关文章

  1. 在过滤器中获取在web.xml配置的初始化参数

    在过滤器中获取在web.xml配置的初始化参数   例如 <filter> <filter-name>cross-origin</filter-name> < ...

  2. Tomcat 中会话超时的相关配置

      QC同事提到似乎有时Tomcat的会话超时表现有问题,记录一下可能用到的配置. 1)超时时间的设定       tomcat的会话超时可以在多个级别上设置:tomcat实例级别.Web应用级别.s ...

  3. Tomcat 中如何给 web 项目配置虚拟目录的方法

    为什么要给 web 项目配置虚拟目录? 初学 JavaWeb 时,会发现只要我们把 web 项目放到 Tomcat 的 webapps 目录下,再通过 http://localhost:8080/项目 ...

  4. Tomcat学习笔记 - 错误日志 - Tomcat部署项目或修改xml配置出现无法保存的情况(拒绝访问)

    原因分析:(windows下) 可能有人会发现在编辑好 tomcat-users.xml 文件后无法保存,原因是使用的用户没有权限修改文件,可能是把 Tomcat 发行包放到了一个需要管理员权限才能修 ...

  5. tomcat支持https的server.xml配置

    访问地址:https://127.0.0.1/testWeb/mySevlet?url=123&action=aaa server.xml: <?xml version='1.0' en ...

  6. spring中的aop的xml配置方式简单实例

    aop,即面向切面编程,面向切面编程的目标就是分离关注点,比如:一个骑士只需要关注守护安全,或者远征,而骑士辉煌一生的事迹由谁来记录和歌颂呢,当然不会是自己了,这个完全可以由诗人去歌颂,比如当骑士出征 ...

  7. 【IDEA】IDEA中maven项目pom.xml依赖不生效解决

    问题: 今天在web项目中需要引入poi相关jar包.查看之下才发现pom.xml中的依赖虽然已经下载到了本地仓库 repository,但是却没有加入到项目路径的 Extenal Libraries ...

  8. idea中pom.xml没有工作 IDEA中maven项目pom.xml依赖不生效解决

    问题: 今天在web项目中需要引入poi相关jar包.查看之下才发现pom.xml中的依赖虽然已经下载到了本地仓库 repository,但是却没有加入到项目路径的 Extenal Libraries ...

  9. springMVC框架中,在hib-config.xml配置sqlserver2008数据库连接的代码

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">     ...

随机推荐

  1. PHP ftp_nb_continue() 函数

    定义和用法 ftp_nb_continue() 函数连续获取/发送文件.(无阻塞) 该函数返回下列值之一: FTP_FAILED(发送/获取失败) FTP_FINISHED(发送/获取成功) FTP_ ...

  2. HBase自定义MapReduce

    HBase表数据的转移 在Hadoop阶段,我们编写的MR任务分别进程了Mapper和Reducer两个类,而在HBase中我们需要继承的是TableMapper和TableReducer两个类. 目 ...

  3. [SCOI2009]迷路(矩阵快速幂) 题解

    Description windy在有向图中迷路了. 该有向图有 N 个节点,windy从节点 0 出发,他必须恰好在 T 时刻到达节点 N-1. 现在给出该有向图,你能告诉windy总共有多少种不同 ...

  4. php开发面试题---vue面试题(vue.js的好处及作用)

    php开发面试题---vue面试题(vue.js的好处及作用) 一.总结 一句话总结: 双向数据绑定:在做ajax的时候,更新实在是太方便了 用数据绑定的思想,vue可以简单写单个页面,也可以写一个大 ...

  5. Java-Class-FC:java.lang.StringBuilder

    ylbtech-Java-Class-FC:java.lang.StringBuilder 1.返回顶部   2.返回顶部 1. @Override public String toString() ...

  6. flask json

    导入 from flask import Flask,jsonify 1.列表 def index(): arr=['mkdir','md','touch'] return jsonify(arr) ...

  7. Unity通过Jar包调用Android

    Unity通过Jar包调用Android 我们会需要面对下面几个问题,我们一个一个来解决: 怎样在Android Studio中打Jar包 怎样打一个Unity使用的Jar包 怎样在Unity工程中使 ...

  8. Linux的命名空间

    1. 为什么提供命名空间 命名空间是一种轻量级的虚拟化手段. 传统的虚拟化软件,是虚拟化多个不同的操作系统,对共享资源的限制很大. 通过提供命名空间,可以让进程与进程之间,用户与用户之间彼此看不到对方 ...

  9. FVWM_SMALLEST_CONFIG

    ... # ----------------------------------------------------------------- # HANDBOOK: # http://yaoqian ...

  10. JUC源码分析-集合篇(一)ConcurrentHashMap

    JUC源码分析-集合篇(一)ConcurrentHashMap 1. 概述 <HashMap 源码详细分析(JDK1.8)>:https://segmentfault.com/a/1190 ...