MENU

Tomcat初步

September 5, 2018 • Read: 3177 • JSP阅读设置

Tomcat的目录结构

  • bin/ 二进制本身的可执行文件和脚本
  • conf/ 配置文件目录
  • logs/ 日志目录
  • lib/ 服务器和web应用可加载的类目录
  • webapps/ web应用所存放的目录
  • word/ Tomcat的工作目录
  • temp/ 存放临时产生的文件

Tomcat配置文件

  • conf/server.xml 服务器的配置文件
  • conf/web.xml 定义所有web应用的配置
  • conf/tomcat-user.xml 定义了Tomcat用户的信息

修改server.xml文件

启动Tomcat是通过双击bin/startup.bat,测试是否启动成功,主要是通过访问localhost:8080,如果后期有需要修改访问的端口,可以通过修改conf/server.xml文件中的port参数,具体见下图

进入Tomcat主页后看到右边三个按钮,点击会出现账号密码进行登陆,但是在此之前需要先设置user信息,进入conf/tomcat-users.xml

配置tomcat-users.xml文件

针对第三个按钮“Host Manager”,配置角色时一定把角色配全。修改tomcat-users.xml 文件,加入如下代码:

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

配置tomcat-users.xml文件后,重新启动tomcat服务。在浏览器的地址栏中输入localhost:8080,回车。成功访问tomcat,点击要访问的 “Host Manager”在弹出的“身份验证”框中输入用户名:tomcat,密码:tomcat,点击登录按钮,然后就可以顺利访问“Host Manager”了。

角色role信息

tomcat主页有三个按钮:

  • Server Status
  • Manager App
  • Host Manager

前两个按钮和manager相关,具体角色名为:

  • manager-gui - allows access to the HTML GUI and the status pages
  • manager-script - allows access to the text interface and the status pages
  • manager-jmx - allows access to the JMX proxy and the status pages
  • manager-status - allows access to the status pages only

第三个按钮和admin相关,具体角色名为

  • admin-gui - allows access to the HTML GUI and the status pages
  • admin-script - allows access to the text interface and the status pages

如果不注重安全性,只是测试用的话,对应部分可以简单地写成下面这个样子:

<role rolename="admin"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
Last Modified: October 7, 2018
Archives Tip
QR Code for this page
Tipping QR Code