`

如何修改TOMCAT的默认主页为你自己项目的主页

    博客分类:
  • java
 
阅读更多
(最合适的)
最直接的办法是,删掉tomcat下原有Root文件夹,将自己的项目更名为Root。

我在$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页面的内容。
(一)
转】 如何修改TOMCAT的默认主页为你自己项目的主页
启动tomcat之后,在猫页上有这么一段话:
As you may have guessed by now, this is the default Tomcat home page. It can be found on the local filesystem at:
$CATALINA_HOME/webapps/ROOT/index.html
这就说明,无论你怎么折腾你自己的web.xml文件,对不起,tomcat只认它自己的web.xml定义的welcome页面。
而<welcome-file-list>标签上的这段注释:
<!-- 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.
-->
修改过程
1.不要碰conf目录下的那个web.xml文件,让它老死在那里吧。
2.把原来的ROOT目录清空,里面什么都不要留。删掉或者改名随便你怎么弄都成。只要清空就好。
3.发布你自己的项目到ROOT目录下,用war包发布或者用直接拷贝的都一个效果。保证index.html/index.htm/index.jsp其中一个存在于ROOT目录下。
4.删除%CATALINA%/work目录下的一切。我就是没有清理这个目录,导致http://localhost:8080永远都是那只猫~~~~郁闷
5.通知服务商重启tomcat。
(二)

这里把用指定项目的主页替换tomcat主页的方法记录一下:

1、 更改tomcat端口为80

tomcat目录conf下找到server.xml打开,找到

<Connector port="80" protocol="HTTP/1.1"

connectionTimeout="0"

redirectPort="8443" URIEncoding="gb2312"/>

port改为80.

如端口80被占用,解决方法:解决:wincmd命令窗口输入netstat -abn ->c:/port80.txt 然后到cport80.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>

-

资料引用:http://www.knowsky.com/535134.html

分享到:
评论

相关推荐

    tomcat配置默认访问项目

    tomcat配置默认访问项目,配置后可直接通过ip地址加端口号访问项目

    Tomcat设置默认启动项目

    Tomcat设置默认启动项目,顾名思义,就是让可以在浏览器的地址栏中输入ip:8080,就能访问到我们的项目。

    修改tomcat项目的图标

    可以用于修改tomcat项目的项目图标,不修改的时候,默认是tomcat的默认的猫图标

    Tomcat访问项目,去掉项目名配置

    在Tomcat启动时会去webapps下访问默认ROOT目录下的应用程序,这就导致你始终不能直接访问的原因 切记切记切记,这才是关键 先将它原始就有的ROOT删掉 把 自己的项目包“oa.war” 改成 “ROOT.war” 即可,因为下面的...

    linux修改tomcat默认访问项目的具体步骤(必看篇)

    如果更改tomcat服务器下的默认访问工程,需要修改tomcat/conf/server.xml配置文件。 打开server.xml可以找到类似下面的配置: unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false&gt; ...

    设置tomcat默认打开的项目

    2.在里面添加下面一句话 其中docBase为项目绝对路径,path为相对路径(相对于默认的webapps的路径) 此时使path为空,访问localhost即访问webapps也即访问docBase 打开安装目录下的bin文件找到startup.bat点开启动...

    tomcat解析多个项目配置

    tomcat解析多个项目配置,并设置默认访问项目。

    RHEL7.0下的TOMCAT安装、配置及优化1.02.docx

    RHEL7.0下的TOMCAT安装、配置及优化 一、安装前准备 3 二、JDK安装 2.1、建立tomcat用户 2.2、将JDK安装文件上传到服务器 2.3、安装JDK 2.4、配置JDK环境变量 ...4.2、修改tomcat默认的maxThread(最大并发数)

    Spring Boot项目导出war包放到tomcat运行跳转到页面出现404报错

    Spring Boot项目导出war包放到tomcat运行跳转到页面出现404报错

    jsp项目中更改tomcat的默认index.jsp访问路径的方法

    如何更改tomcat的默认index.jsp访问路径,jsp的工程下有一个叫做WEB-INF文件夹下的web.xml打开它,按照下面的方法即可修改

    Tomcat 7 API文档

    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat ...

    Tomcat默认程序发布路径的使用与修改方法讲解

    今天小编就为大家分享一篇关于Tomcat默认程序发布路径的使用与修改方法讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

    tomcat安装包jakarta-tomcat-5.0.18.exe

     Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在...

    tomcat虚拟内存设置

    tomcat默认可以使用的内存为128MB,在较大型的应用项目中,这点内存是不够的,轻微时,会使系统性能急剧下降,严重时,将导致系统无法运行,影响系统的稳定性。

    10、修改tomcat端口项目1

    1、修改8080端口为80811、tomcat的默认端口是8080,但该端口不是tomcat的唯一端口,可以通过修改tomat的配置文件进行修改,打开tomca

    apache-tomcat-8.5.40

    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat ...

    dubbo-admin监控工具 jdk8 tomcat8亲测有效

    dubbo-admin 针对jdk8和tomcat8 ,本人自己项目刚使用,亲测绝对有效。1、 下载解压后将包放到tomcat8的webapps下 2、修改dubbo-admin-2.5.7/WEB-INF/dubbo.properties中的address为对应的zookeeper地址即可,启动...

    apache-tomcat-8.0.48

    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat ...

    apr库(tomcat优化)

    tomcat默认采用的BIO模型,在几百并发下性能会有很严重的下降。tomcat自带还有NIO的模型,另外也可以调用APR的库来实现操作系统级别控制。 NIO模型是内置的,调用很方便,只需要将上面配置文件中protocol修改成org....

Global site tag (gtag.js) - Google Analytics