配置TOMCAT 修改默认ROOT路径
本文转载http://xxs673076773.iteye.com/blog/1134805
我在$tomcat/webapps/下建了个myjsp目录作为我网站的默认目录,在myjsp中有一个a.jsp文件,该文件要作为我网站的默认主页。
修改配置文件:
首先,修改$tomcat/conf/server.xml文件。
在server.xml文件中,有一段如下:
……
<engine name="Catalina" defaultHost="localhost">
<host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
……
<host>
</engine>
……
在<host></host>标签之间添加上:
<Context path="" docBase="myjsp" debug="0" reloadable="true" />
path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;
docBase是虚拟目录的路径,它默认的是$tomcat/webapps/ROOT目录,现在我在webapps目录下建了一个myjsp目录,让该目录作为我的默认目录。
debug和reloadable一般都分别设置成0和true。
然后,修改$tomcat/conf/web.xml文件。
在web.xml文件中,有一段如下:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:
<welcome-file>a.jsp</welcome-file>
更改端口
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />
将port "8080"改成你的端口
保存上述两个文件后重启tomcat,在浏览器地址栏内输入"http://localhost:8080/",显示a.jsp页面的内容。
$CATALINA_HOME/webapps/ROOT/index.html
<!-- If you define welcome files in your own application's web.xml -->
<!-- deployment descriptor, that list *replaces* the list configured -->
<!-- here, so be sure that you include any of the default values that -->
<!-- you wish to include.-->
这里把用指定项目的主页替换tomcat主页的方法记录一下:
1、 更改tomcat端口为80
在tomcat目录conf下找到server.xml打开,找到
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="0"
redirectPort="8443" URIEncoding="gb2312"/>
port改为80.
如端口80被占用,解决方法:解决:在win的cmd命令窗口输入netstat -abn ->c:/port80.txt 然后到c盘port80.txt文件中找到占用80端口的程序pid,记下pid。打开任务管理器,点击“查看”/选择列,勾选“PID(进程标识符)”,然后单击“进程”标签,找到80端口对应的pid,就可以看到是那个程序占用的了,更改这个程序的port,再重启这个程序,使更改生效。
2、 设置默认访问主页为指定项目。
在server.xml中找到
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
在标签中间插入:
<Context path="" docBase="xbwl" debug="0" reloadable="true"/>
docBase="xbwl" xbwl即为指定的项目。
完整如下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="xbwl" debug="0" reloadable="true"/>
</Host>
(三)
可以通过以下操作实现更改tomcat的默认主页所在的目录。
替换并保存一下内容为conf文件夹下的server.xml
<?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.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="80
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="C:\Tomcat6\webapps\pms" workDir="C:\Tomcat6\webapps\pms"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
(四)
方法一:(适合对服务器中单个站点的设置)
(d:\demo\为站点根目录)
在Tomcat中,默认主页为:index.html,index.htm,index.jsp
如果需要使用其他页面作为默认主页,需要配置WEB-INF文件夹下的web.xml文件:
如上例中:
在D:\demo\WEB-INF\文件夹中建立文件web.xml:
内容如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”2.4″
xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd“>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>
方法二:(以下设置将应用于该服务器下所有的站点)推荐使用
打开文件conf/web.xml,找到这段代码:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在中间加入你想要的文件名即可。
如:我想让hello.jsp成为默认首页,我将上面那段代码改成:
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
配置TOMCAT 修改默认ROOT路径的更多相关文章
- maven的安装、路径配置、修改库文件路径和eclipse中的配置、创建maven工程。
注:本文来源于:杨四郎2018 <maven的安装.路径配置.修改库文件路径和eclipse中的配置.创建maven工程> 一.maven的安装 首先,先到官网去下载maven.这里是官 ...
- 【转】Tomcat的默认访问路径
放在外网的应用,用户多是直接输入域名访问,相信没有哪个后面还加个尾巴,而Tomcat的默认目录是ROOT,所以我们需要更改其默认目录. 更改Tomcat的默认目录很简单,只需要修改server.xml ...
- Mysql5.6.24 zip解压缩版配置及修改默认编码方法
win64位下载地址: http://dev.mysql.com/downloads/file.php?id=456319 下载完毕后解压 配置环境变量 在Path后加上mysql解压后bin文件夹所 ...
- Docker 修改默认存储路径的一个方法
1. 前期安装创建centOS的虚拟机时发现自己对linux的挂载点不清楚, 造成挂载点的分配不太均匀,如图: root / 节点的大小设置的比较小 /home路径设置的一直比较大 但是docker ...
- ubuntu 修改默认root及密码
安装完Ubuntu后忽然意识到没有设 置root密码,不知道密码自然就无法进入根用户下.到网上搜了一下,原来是这麽回事.Ubuntu的默认root密码是随机的,即每次开机都有一个新的 root密码.我 ...
- 更换jupyter notebook风格主题、修改默认工作路径(Ubuntu系统和Win系统)
默认的风格对代码关键词的颜色提醒很不明显,而且白色背景长久使用非常刺眼,所以考虑更换主题. 在更换途中,发现代码输出行,前几个字符被遮挡显示不出来,找了很久才解决,备忘一些要点. 1:替换主题方法 h ...
- tomcat修改默认端口
1.webserver: tomcat2.version: Apache Tomcat/7.0.293.operation: 修改默认端口 3.1 修改tomcat目录下的/conf/server ...
- Ubuntu修改默认root及密码
Ubuntu的默认root密码是随 机的,即每次开机都有一个新的 root密码. 我们可以在终端输入命令 sudo passwd, 然后输入当前用户的密码,enter, 终端会提示我们输入新的密码并确 ...
- 【SecureCRT配置】修改默认卷屏行数当做一个操作,屏幕输出有上百行,当需要将屏幕回翻时,这个设置会有很大帮助,默认为500行,可以改为10000行,不用担心找不到了。 选项 => 全局选项 => Default Session => Edit Default Settings => Terminal => Emulation => Scrollback 修改为32000。
SecureCRT配置屏幕内容输出到log文件 SecureCRT看不到前几分钟操作的内容,或者想把通过vi命令查看的日志输出到log文件(在懒得下载日志文件的情况下),所以接下来就这样操作: 文件保 ...
随机推荐
- Makefile 中:= ?= += =的区别【转】
转自:http://www.cnblogs.com/wanqieddy/archive/2011/09/21/2184257.html 在Makefile中我们经常看到 = := ?= +=这几个赋值 ...
- Mac下搭建svn服务器和XCode配置svn
先打开命令行终端. 1.创建svn repository svnadmin create /yourpath/svnroot/repository 2.配置svn用户权限. / yourpath /s ...
- SecureCRT 设置中文编码
http://www.diybl.com/course/6_system/linux/Linuxjs/20090326/163546.html 装了个secureCRT,可老是出现乱码 于是 ...
- java使用ssh访问Linux的项目jscraft
一.gradle地址 // https://mvnrepository.com/artifact/com.jcraft/jsch compile group: 'com.jcraft', name: ...
- 调用oracle 各种报错总结---待续
ORA-01747: user.table.column, table.column 或列说明无效 原因之一是sql语句拼接错误,多了逗点:二是使用到了oracle的关键字所致 ORA-02449: ...
- caffe make 编译
其实嘛,出现这个的原因在于,已经编译过啦,没有任何改动,那还烦劳编译啥呢. 那Linux又是如何知道已经编译过了呢? 那就要看makefile的规则啦.makefile的规则是所想产生的文件需要依赖很 ...
- yii2 数据库操作详解(转载)
开始使用数据库首先需要配置数据库连接组件,通过添加 db 组件到应用配置实现("基础的" Web 应用是 config/web.php),DSN( Data Source Name ...
- 怎么使用 bat 使用日期时间重命名文件名
d: rename A.txt "A%date:~0,4%-%date:~5,2%-%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%_backu ...
- perl的匿名引用
perl中列表不能嵌套,只能通过引用的方式构建复杂的结构.引用其实就是c中的指针,只不过perl中对指针,也就是一个地址的声明和取值有自己的一套方法. 1.先复习普通标量的引用方法: [vagrant ...
- Meta Blogging
Meta Blogging 由来 偶然想到说如果哪一天cnblogs挂了,那之前记录的随笔怎么办?可不可以把它们给download下来本地保存一份.正好看到有个库叫requests, 干嘛不试试看呢. ...