yuxing

目标:

我在$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页面的内容。


另外的方法

一.设置端口
在server.xml文件中找到<!--   Define a non-SSL HTTP/1.1 Connector on port 8080, change it to 80.   -->
     < Connector
port ="80"                maxHttpHeaderSize ="8192"
               maxThreads ="150"  minSpareThreads ="25"  maxSpareThreads ="75"
               enableLookups ="false"  redirectPort ="8443"  acceptCount ="100"
               connectionTimeout ="20000"  disableUploadTimeout ="true"   />把其中的port改为你想要的端口即可。
二 .设置虚拟路径
  要在TOMCAT中设置虚拟路径/abc/,映射到D:\temp中,可以有两种方法:
1. 在$Tomcat_home$\conf\Catalina\localhost路径下新建一个XML文件,注意:XML文件的名称必须和虚拟路径的名称相同,本例为abc.xml。内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<Context    docBase="D:\temp"    reloadable="true"    debug="0"/>//此处不用写" path="/abc",写不写效果一样

这样就设置好了/abc的虚拟路径
2.
编辑server文件(%tomcathome%\conf\server.xml)
因为在tomcat启动时要读取server文件的信息,所以更改server文件后,一定要重新启动tomcat。
举个例子:
我们打算建立一个myjsp的虚拟目录,只要在%tomcathome%\conf\server.xml文件,在<host>标签中加入文件中加入如下代码即可:
<Context path="/myjsp" docBase="c:\myjsp" debug="0" reloadable="true" crossContext="true"></Context>
其中,path为我们要建立的虚拟目录,docBase为实际目录在硬盘上的位置。

分类:

技术点:

相关文章:

  • 2022-01-10
  • 2021-12-15
  • 2021-08-13
  • 2021-08-31
  • 2021-11-19
  • 2021-12-09
猜你喜欢
  • 2021-10-09
  • 2021-09-30
  • 2021-08-11
  • 2021-12-15
  • 2021-09-26
相关资源
相似解决方案