Tomcat8.0.21 forgot user name and password when logging in

Source: Internet
Author: User

  This semester is probably not long, April, in order to learn Java EE, installed Tomcat. It took so long to forget the username and password, so I couldn't get into Tomcat's admin interface. Baidu (in fact, I also want to use Google) a bunch, almost all modify the user profile, may be the version of the difference, for my version is not much use. In fact, as long as you follow the instructions of Tomcat to be able to solve, the premise is that the English Foundation is better, in fact, technical articles than literature and four-level examination understood more, language is straightforward, never beat around the bush.

Here are the steps to solve this problem:

Find the location of the Tomcat configuration file and modify the Tomcat-users.xml

my profile is in D:\Program Files\apache software foundation\tomcat 8.0\conf. This directory contains all the configuration files for Tomcat, including Content.xml,server.xml,web.xml,tomcat-users.xml, each with its own role, What we need to change is the user-related tomcat-users.xml.

 Open the Tomcat-users.xml configuration file (I omitted some comments):

1   <?XML version= ' 1.0 ' encoding= ' cp936 '?>2   <tomcat-usersxmlns= "Http://tomcat.apache.org/xml"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://tomcat.apache.org/xml tomcat-users.xsd"5 version= "1.0">6   <!--7 note:by Default, no user is included in the "Manager-gui" role required8 To operate the "/manager/html" Web application. If you wish the use of this app,9 You must define such a user-the username and password is arbitrary.Ten  - One   <!-- Anote:the sample user and role entries below is wrapped in a comment -And thus is ignored when the reading this file. do not forget to remove -<!.. .. > that surrounds them. the  - -   <rolerolename= "Tomcat"/> -  <rolerolename= "Role1"/> -  <Userusername= "Tomcat"Password= "Tomcat"Roles= "Tomcat"/> +  <Userusername= "both"Password= "Tomcat"Roles= "Tomcat,role1"/> -   <Userusername= "Role1"Password= "Tomcat"Roles= "Role1"/> + </tomcat-users>

  The comments in the 7-11 lines of the configuration file are clear: By default, no user is included in the "Manager-gui" role that can manipulate the "/manager/html" page, and if you want to open the app, you can define a user with a user name and password. So I added a few lines of code, the modified configuration file is this:

1 <?XML version= ' 1.0 ' encoding= ' cp936 '?>2 <tomcat-usersxmlns= "Http://tomcat.apache.org/xml"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://tomcat.apache.org/xml tomcat-users.xsd"5 version= "1.0">6 <!--7 note:by Default, no user is included in the "Manager-gui" role required8 To operate the "/manager/html" Web application. If you wish the use of this app,9 You must define such a user-the username and password is arbitrary.Ten  - One <!-- A note:the sample user and role entries below is wrapped in a comment - And thus is ignored when the reading this file. do not forget to remove - <!.. .. > that surrounds them. the  - -   <rolerolename= "Tomcat"/> -   <rolerolename= "Role1"/> -   <Userusername= "Tomcat"Password= "Tomcat"Roles= "Tomcat"/> +   <Userusername= "both"Password= "Tomcat"Roles= "Tomcat,role1"/> -   <Userusername= "Role1"Password= "Tomcat"Roles= "Role1"/>
<role rolename= "Manager-gui"/> <user username= "admin" password= "admin" roles = "Admin-gui"/> </tomcat-users>

   Added <role RoleName= "Manager-gui"/> <user username= "admin" password= " Admin " Roles=" Manager-gui "/> After these two lines of code added a role Manager-gui, and added a user, username is admin, password is admin, role is Manager-gui, remember to ctrl+s save after modification.

Second, restart Tomcat

  command line how to restart I'm not quite sure, later on to the Linux platform when it is more certain to use the command line, let's first use graphical tools. But it didn't seem to provide the restart option, I had to stop the service and start again. When it restarts, Tomcat reads the XML configuration file again, and the user with administrator privileges is added. In browser input 192.168.1.106:8080, the browser will access the default page

There are 3 buttons on the right Henmi of this page, we just configured the 1th and 2nd buttons, click the two button, enter the username and password to access the/manage/html and/manage/status pages.

Iii. New Problems encountered

 However, if you click on the 1th or 3rd button, the following situation will appear:

  In this error page has given a detailed solution, if the English level can also and willing to take a look at the heart, we know how to solve the problem. Just now we have added a Manager-gui role and added a user with the appropriate permissions for this role. This time we just need to add another Admin-gui role and add a user who is part of this role. I added 39, 402 lines of code in the original config file:

Save after modification, this time, restart Tomcat, you can access the original 403 Forbidden/host-manager/html page

Iv. The ultimate Solution

but it's a hassle to remember two usernames and passwords, what do you do?

From the section in front of the configuration file <user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/><user username= "both" password= "Tomcat " roles=" Tomcat,role1"/> can be seen, so that a user is given two roles at the same time. So I changed the config file to this:<role rolename= "Admin-gui"/> <user username= "admin" password= "admin" roles= " Admin-gui,manager-gui "/> To restart Tomcat after the save, this time finally worked.

Five, sentiment

  When encountering the problem, the document or the configuration file itself is the best material, should be good at imitating the writing of the document to try to guess and understand the meaning of each parameter, at the same time must have a certain degree of English reading comprehension ability.

Tomcat8.0.21 forgot user name and password when logging in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.