Tomcat去除端口号和项目名

方法一:

在一个项目结束的时候,往往根据需要直接映射到一个IP地址上。此时就需要去除端口和项目名了,在访问的时候。下面根据具体的例子提供一种实现方法。

一、去掉项目名称

把<ContextdocBase="D:\apache-tomcat-6.0.20\webapps\TCS(项目所在路径)"path=""/>加到D:\apache-tomcat-6.0.20\conf\server.xml文件的<Host&gt;</Host>元素下,即可去掉项目名称。如下: <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"> <Context docBase="D:\apache-tomcat-6.0.20\webapps\TCS" path="" />

</Host>二、去掉端口号 打开TOMCAT_HOME\conf\server.xml中查找原始的端口号(如8080),修改为80后,即可在访问时不用输入端口号。不过要注意防止其它程序占用80端口。

方法二:

1.修改TomcatwebappsROOTWEB-INF下的web.xml文件如下:

<?xml version="1.0"encoding="ISO-8859-1"?>

<!DOCTYPE web-app
<wbr><wbr><wbr> PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"<br><wbr><wbr><wbr>"http://java.sun.com/dtd/web-app_2_3.dtd"&gt;</wbr></wbr></wbr></wbr></wbr></wbr>

<web-app>
<wbr><wbr><wbr>&lt;welcome-file-list&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;<br><wbr><wbr><wbr>&lt;/welcome-file-list&gt;<br> &lt;/web-app&gt;<br> 2.在TomcatwebappsROOT建立index.html文件,写入如下代码:</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<head><metahttp-equiv="REFRESH" content="1;url=../工程文件夹"></head>
3.修改Tomcat/conf下的server.xml文件,把8080端口改成80:

<wbr><wbr><wbr>&lt;!-- Define a non-SSL HTTP/1.1 Connector on port 8080--&gt;<br><wbr><wbr><wbr>&lt;Connector port="80" maxHttpHeaderSize="8192"<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>maxThreads="150" minSpareThreads="25" maxSpareThreads="75"<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>enableLookups="false" redirectPort="8443" acceptCount="100"<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>connectionTimeout="20000" disableUploadTimeout="true" /&gt;<br> 此时在浏览器键入本地IP即可访问工程网站!</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>


你可能感兴趣的:(tomcat)