赛迪网 > IT技术 Java > Java大图列表
  IT资讯搜索
 
IT产品搜索
[程序开发][网管世界][网络安全][数据库技术]
[操作系统][嘉宾聊天·在线访谈][活动集锦]
[精彩专题][Symantec专区][订阅IT技术周刊]
[开发论坛][网管论坛][安全论坛][数据库论坛]
[操作系统论坛][Sybase专区][IBM dW技术专区]
[病毒求助][病毒与漏洞播报][文档·源码下载]

TomCat 多虚拟站点配置

发布时间:2008.03.06 04:57     来源:赛迪网    作者:ycoe

首先是下载工具:

  我建议初学者用Editplus+JDK,我觉得如果用例如JB,Eclipse,JCreator,虽然刚开始的时候比较方便,但是确使初学者门不知道怎样配置环境变量,从而难以达到知其然,知其所以然的地步。

  可以通过如下地址下载:

Editplus(最新版本是v2.11):http://count.skycn.com/softdown.php?id=3641&url=http://sc-http.skycn.net/down/epp211a_cn.exe JDK(最新版本是Java2sdk1_4_2):http://count.skycn.com/softdown.php?id=3116&url=http://sc-http.skycn.net/down/j2sdk-1_4_2-windows-i586.exe(这是For Windows)

  然后就是安装JDK,我是把它装到从c:\JDK目录下面。

  然后设置CLASSPATH的问题了:

  正如操作系统利用PATH来搜索可执行程序一样,Java运行环境也会遍历CLASSPATH来查找类,即便是HelloWorld这样简单的程序,JVM也会遍历CLASSPATH定义的每一个路径,直到找到相应的文件为止。

  相信大家用的系统不是2k就是XP,然后就应当如下设置Path:

  我的电脑->属性->高级->环境变量

  然后在环境变量的Path后面追加: C:\JDK\bin;.;C:\JDK\lib

  也可以这样配置:C:\JDK\bin;.;C:\JDK\lib\dt.jar;C:\JDK\lib\tools.jar

  ★记住:环境变量中的 . 切记不能少,它表示当前路径,如果少掉出现的错误等会就说!

  dt.jar是关于运行环境的类库,tools.jar是关于一些工具的类库

  如果没有配置:C:\JDK\bin,则会出现 “ javac' 不是内部或外部命令,也不是可运行的程序或批处理文件。”这样的错误。

  下面我们就写一个示例程序:

  打开Editplus,新建一个Java文件,请照着如下输入,要一字不漏,并且分清大小写:

public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello,World!");
}
}

  然后把这个文件保存(ctrl + s)到HelloWorld.java,Java是分大小写的,所以大小写一定要分清,是HelloWorld.java不是helloworld.java或者其他。

  运行:开始->运行->cmd

  在控制台中把目录切换到当前目录:

javac HelloWorld.java
java HelloWorld

  你就会在控制台上看见输出的Hello,World!

  javac是编译命令,它把HelloWorld.java编译成HelloWorld.class

  java就是解释命令,JVM把HelloWorld.class解释执行.

  在这个时候:

  1、如果出现Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
那就是你在环境变量中没有加上那个.(dot)

  2、如果出现Exception in thread "main" java.lang.NoSuchMethodError: main
或者HelloWorld.java:1: Public class helloworld must be defined in a file called

"HelloWorld.java".

  那就是你没有分清大小写的写入这个HelloWorld,或者保存得时候没有保存为HelloWorld.java。这个名字一定要跟public class的名字一样

  对于环境变量的问题就说到这里,下面我先所说怎么在Editplus里面编译和运行,在Tools->参数设置->配置用户工具

  1.添加工具(添加应用程序)

  菜单文字:Compile Java Program

  程序:C:\JDK\bin\javac.exe

  参数:文件名称

  初始目录:文件目录

  2.添加工具(添加应用程序)

  菜单文字:Run Java Program

  程序:C:\JDK\bin\java.exe

  参数:文件名称(不含扩展名)

  初始目录:文件目录

  工具组名称可以随便添,比如Debug Java Program。

  然后在Tools的下拉菜单中,你就会看见Compile Java Program以及Run Java Program这两个选项,以后你就可以利用ctrl + 1编译和ctrl +2运行程序了

下面我们讨论Servlet的运行环境:

  要运行Servlet,则需要JSP/Servlet container,我建议初学者用Tomcat。

Tomcat(最新版本5.0):http://cvs.apache.org/builds/jakarta-tomcat-5/nightly/jakarta-tomcat-5-bin-20030725.zip

  然后把这个压缩包解压到:

  C:\Tomcat

  然后再配置环境变量;添加三个系统变量:

JAVA_HOME: C:\JDK
TOMCAT_HOME: C:\Tomcat
CLASSPATH: %JAVA_HOME%\lib;%TOMCAT_HOME%\lib

  Tomcat的环境变量就配置完毕了,下面检验Tomcat是否能够运行:

  在控制台中转到C:\Tomcat\bin这个目录,运行startup,然后回出现一个窗口,连跳一大串东西,最后表示Server已经运行。

  在浏览器中输入http://localhost:8080,出现欢迎界面,则表示Tomcat没问题了。然后和上面一样,写入你的第一个Servlet。

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>");
out.println("This is my first Servlet");
out.println("</title></head><body>");
out.println("<h1>Hello,World!</h1>");
out.println("</body></html>");

}
}

  然后照样用javac HelloWorld.java来编译这个文件,如果出现无法import javax.servlet.*

  那么就是应该把C:\Tomcat\common\lib里面的servlet.jar文件拷贝到C:\JDK\jre\lib\ext中,再次编译,就没有问题了!

  然后在Tomcat目录里面的C:\Tomcat\webapps\ROOT里面按如下的文件结构:

ROOT\index.html
ROOT\welcom.jsp
ROOT\WEB-INF\lib\MyServlet.jar(如果你的servlet的.class打成了.jar文件,则放在lib下面)
ROOT\WEB-INF\classes\HelloWorld.class(把上面生成的HelloWorld.class文件放在这个里面)

  然后在浏览器中输入http://localhost:8080/servlet/HelloWorld,于是Server众望所归的报错了:Error 404--Not Found

  怎么回事呢?

  Servlet必须使用C:\Tomcat\webapps\ROOT\WEB-INF这个目录下面的web.xml文件进行注册,用EP打开这个web.xml文件,在里面加入:

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/helloworld</url-pattern>
</servlet-mapping> 

  这样的结构

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

  表示指定包含的servlet类。而以下的结构:

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>

   表示指定HelloServlet应当映射到哪一种URL模式。
根据conf\server.xml里面的说明和范例,我样可以编写出下面一个配置文件:
    我把配置文件全部粘出来了,但大部分都是默认的,还有注释部分。大可不理,只修改了几部分,后面都有说明!

  1< !-- Example Server Configuration File -->
  2< !-- Note that component elements are nested corresponding to their
  3     parent-child relationships with each other -->
  4
  5< !-- A "Server" is a singleton element that represents the entire JVM,
  6     which may contain one or more "Service" instances.  The Server
  7     listens for a shutdown command on the indicated port.
  8
  9     Note:  A "Server" is not itself a "Container", so you may not
 10     define subcomponents such as "Valves" or "Loggers" at this level.
 11 -->
 12
 13< Server port="8005" shutdown="SHUTDOWN">
 14
 15  < !-- Comment these entries out to disable JMX MBeans support used for the
 16       administration web application -->
 17  < Listener className="org.apache.catalina.core.AprLifecycleListener" />
 18  < Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
 19  < Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
 20  < Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
 21
 22  < !-- Global JNDI resources -->
 23  < GlobalNamingResources>
 24
 25    < !-- Test entry for demonstration purposes -->
 26    < Environment name="simpleValue" type="java.lang.Integer" value="30"/>
 27
 28    < !-- Editable user database that can also be used by
 29         UserDatabaseRealm to authenticate users -->
 30    < Resource name="UserDatabase" auth="Container"
 31              type="org.apache.catalina.UserDatabase"
 32       description="User database that can be updated and saved"
 33           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
 34          pathname="conf/tomcat-users.xml" />
 35
 36  < /GlobalNamingResources>
 37
 38  < !-- A "Service" is a collection of one or more "Connectors" that share
 39       a single "Container" (and therefore the web applications visible
 40       within that Container).  Normally, that Container is an "Engine",
 41       but this is not required.
 42
 43       Note:  A "Service" is not itself a "Container", so you may not
 44       define subcomponents such as "Valves" or "Loggers" at this level.
 45   -->
 46
 47  < !-- Define the Tomcat Stand-Alone Service -->
 48  < Service name="Catalina">
 49
 50    < !-- A "Connector" represents an endpoint by which requests are received
 51         and responses are returned.  Each Connector passes requests on to the
 52         associated "Container" (normally an Engine) for processing.
 53
 54         By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
 55         You can also enable an SSL HTTP/1.1 Connector on port 8443 by
 56         following the instructions below and uncommenting the second Connector
 57         entry.  SSL support requires the following steps (see the SSL Config
 58         HOWTO in the Tomcat 5 documentation bundle for more detailed
 59         instructions):
 60         * If your JDK version 1.3 or prior, download and install JSSE 1.0.2 or
 61           later, and put the JAR files into "$JAVA_HOME/jre/lib/ext".
 62         * Execute:
 63             %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
 64             $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  (Unix)
 65           with a password value of "changeit" for both the certificate and
 66           the keystore itself.
 67
 68         By default, DNS lookups are enabled when a web application calls
 69         request.getRemoteHost().  This can have an adverse impact on
 70         performance, so you can disable it by setting the
 71         "enableLookups" attribute to "false".  When DNS lookups are disabled,
 72         request.getRemoteHost() will return the String version of the
 73         IP address of the remote client.
 74    -->
 75
 76    < !-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
 77    < Connector
 78port="80"               maxHttpHeaderSize="8192"
 79               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 80               enableLookups="false" redirectPort="8443" acceptCount="100"
 81               connectionTimeout="20000" disableUploadTimeout="true"  URIEncoding="GB2312"/>
 82    < !-- Note : To disable connection timeouts, set connectionTimeout value
 83     to 0 -->
 84
 85    < !-- Note : To use gzip compression you could set the following properties :
 86
 87               compression="on"
 88               compressionMinSize="2048"
 89               noCompressionUserAgents="gozilla, traviata"
 90               compressableMimeType="text/html,text/xml"
 91    -->
 92
 93    < !-- Define a SSL HTTP/1.1 Connector on port 8443 -->
 94    < !--
 95    < Connector port="8443" maxHttpHeaderSize="8192"
 96               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 97               enableLookups="false" disableUploadTimeout="true"
 98               acceptCount="100" scheme="https" secure="true"
 99               clientAuth="false" sslProtocol="TLS" />
100    -->
101
102    < !-- Define an AJP 1.3 Connector on port 8009 -->
103    < Connector port="8009"
104               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
105
106    < !-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
107    < !-- See proxy documentation for more information about using this. -->
108    < !--
109    < Connector port="8082"
110               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
111               enableLookups="false" acceptCount="100" connectionTimeout="20000"
112               proxyPort="80" disableUploadTimeout="true" />
113    -->
114
115    < !-- An Engine represents the entry point (within Catalina) that processes
116         every request.  The Engine implementation for Tomcat stand alone
117         analyzes the HTTP headers included with the request, and passes them
118         on to the appropriate Host (virtual host). -->
119
120    < !-- You should set jvmRoute to support load-balancing via AJP ie :
121    < Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
122    -->
123
124    < !-- Define the top level container in our container hierarchy -->
125    < Engine name="Catalina" defaultHost="ycoe.vicp.net">
126
127      < !-- The request dumper valve dumps useful debugging information about
128           the request headers and cookies that were received, and the response
129           headers and cookies that were sent, for all requests received by
130           this instance of Tomcat.  If you care only about requests to a
131           particular virtual host, or a particular application, nest this
132           element inside the corresponding < Host> or < Context> entry instead.
133
134           For a similar mechanism that is portable to all Servlet 2.4
135           containers, check out the "RequestDumperFilter" Filter in the
136           example application (the source for this filter may be found in
137           "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
138
139           Request dumping is disabled by default.  Uncomment the following
140           element to enable it. -->
141      < !--
142      < Valve className="org.apache.catalina.valves.RequestDumperValve"/>
143      -->
144
145      < !-- Because this Realm is here, an instance will be shared globally -->
146
147      < !-- This Realm uses the UserDatabase configured in the global JNDI
148           resources under the key "UserDatabase".  Any edits
149           that are performed against this UserDatabase are immediately
150           available for use by the Realm.  -->
151      < Realm className="org.apache.catalina.realm.UserDatabaseRealm"
152             resourceName="UserDatabase"/>
153
154      < !-- Comment out the old realm but leave here for now in case we
155           need to go back quickly -->
156      < !--
157      < Realm className="org.apache.catalina.realm.MemoryRealm" />
158      -->
159
160      < !-- Replace the above Realm with one of the following to get a Realm
161           stored in a database and accessed via JDBC -->
162
163      < !--
164      < Realm  className="org.apache.catalina.realm.JDBCRealm"
165             driverName="org.gjt.mm.mysql.Driver"
166          connectionURL="jdbc:mysql://localhost/authority"
167         connectionName="test" connectionPassword="test"
168              userTable="users" userNameCol="user_name" userCredCol="user_pass"
169          userRoleTable="user_roles" roleNameCol="role_name" />
170      -->
171
172      < !--
173      < Realm  className="org.apache.catalina.realm.JDBCRealm"
174             driverName="oracle.jdbc.driver.OracleDriver"
175          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
176         connectionName="scott" connectionPassword="tiger"
177              userTable="users" userNameCol="user_name" userCredCol="user_pass"
178          userRoleTable="user_roles" roleNameCol="role_name" />
179      -->
180
181      < !--
182      < Realm  className="org.apache.catalina.realm.JDBCRealm"
183             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
184          connectionURL="jdbc:odbc:CATALINA"
185              userTable="users" userNameCol="user_name" userCredCol="user_pass"
186          userRoleTable="user_roles" roleNameCol="role_name" />
187      -->
188
189      < !-- Define the default virtual host
190           Note: XML Schema validation will not work with Xerces 2.2.
191       -->
192      < Host name="ycoe.vicp.net" appBase="webapps"
193       unpackWARs="true" autoDeploy="true"
194       xmlValidation="false" xmlNamespaceAware="false">
195
196        < !-- Defines a cluster for this node,
197             By defining this element, means that every manager will be changed.
198             So when running a cluster, only make sure that you have webapps in there
199             that need to be clustered and remove the other ones.
200             A cluster has the following parameters:
201
202             className = the fully qualified name of the cluster class
203
204             name = a descriptive name for your cluster, can be anything
205
206             mcastAddr = the multicast address, has to be the same for all the nodes
207
208             mcastPort = the multicast port, has to be the same for all the nodes
209
210             mcastBindAddr = bind the multicast socket to a specific address
211
212             mcastTTL = the multicast TTL if you want to limit your broadcast
213
214             mcastSoTimeout = the multicast readtimeout
215
216             mcastFrequency = the number of milliseconds in between sending a "I'm alive" heartbeat
217
218             mcastDropTime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
219
220             tcpThreadCount = the number of threads to handle incoming replication requests, optimal would be the same
amount of threads as nodes
221
222             tcpListenAddress = the listen address (bind address) for TCP cluster request on this host,
223                                in case of multiple ethernet cards.
224                                auto means that address becomes
225                                InetAddress.getLocalHost().getHostAddress()
226
227             tcpListenPort = the tcp listen port
228
229             tcpSelectorTimeout = the timeout (ms) for the Selector.select() method in case the OS
230                                  has a wakup bug in java.nio. Set to 0 for no timeout
231
232             printToScreen = true means that managers will also print to std.out
233
234             expireSessionsOnShutdown = true means that
235
236             useDirtyFlag = true means that we only replicate a session after setAttribute,removeAttribute has been called.
237                            false means to replicate the session after each request.
238                            false means that replication would work for the following piece of code: (only for SimpleTcpReplicationManager)
239                            < %
240                            HashMap map = (HashMap)session.getAttribute("map");
241                            map.put("key","value");
242                            %>
243             replicationMode = can be either 'pooled', 'synchronous' or 'asynchronous'.
244                               * Pooled means that the replication happens using several sockets in a synchronous way. Ie,
the data gets replicated, then the request return. This is the same as the 'synchronous' setting except it uses a pool of sockets,
hence it is multithreaded. This is the fastest and safest configuration. To use this, also increase the nr of tcp threads
that you have dealing with replication.
245                               * Synchronous means that the thread that executes the request, is also the
246                               thread the replicates the data to the other nodes, and will not return until all
247                               nodes have received the information.
248                               * Asynchronous means that there is a specific 'sender' thread for each cluster node,
249                               so the request thread will queue the replication request into a "smart" queue,
250                               and then return to the client.
251                               The "smart" queue is a queue where when a session is added to the queue, and the same session
252                               already exists in the queue from a previous request, that session will be replaced
253                               in the queue instead of replicating two requests. This almost never happens, unless there is a
254                               large network delay.
255        -->
256        < !--
257            When configuring for clustering, you also add in a valve to catch all the requests
258            coming in, at the end of the request, the session may or may not be replicated.
259            A session is replicated if and only if all the conditions are met:
260            1. useDirtyFlag is true or setAttribute or removeAttribute has been called AND
261            2. a session exists (has been created)
262            3. the request is not trapped by the "filter" attribute
263
264            The filter attribute is to filter out requests that could not modify the session,
265            hence we don't replicate the session after the end of this request.
266            The filter is negative, ie, anything you put in the filter, you mean to filter out,
267            ie, no replication will be done on requests that match one of the filters.
268            The filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
269
270            filter=".*\.gif;.*\.js;" means that we will not replicate the session after requests with the URI
271            ending with .gif and .js are intercepted.
272
273            The deployer element can be used to deploy apps cluster wide.
274            Currently the deployment only deploys/undeploys to working members in the cluster
275            so no WARs are copied upons startup of a broken node.
276            The deployer watches a directory (watchDir) for WAR files when watchEnabled="true"
277            When a new war file is added the war gets deployed to the local instance,
278            and then deployed to the other instances in the cluster.
279            When a war file is deleted from the watchDir the war is undeployed locally
280            and cluster wide
281        -->
282
283        < !--
284        < Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
285                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
286                 expireSessionsOnShutdown="false"
287                 useDirtyFlag="true"
288                 notifyListenersOnReplication="true">
289
290            < Membership
291                className="org.apache.catalina.cluster.mcast.McastService"
292                mcastAddr="228.0.0.4"
293                mcastPort="45564"
294                mcastFrequency="500"
295                mcastDropTime="3000"/>
296
297            < Receiver
298                className="org.apache.catalina.cluster.tcp.ReplicationListener"
299                tcpListenAddress="auto"
300                tcpListenPort="4001"
301                tcpSelectorTimeout="100"
302                tcpThreadCount="6"/>
303
304            < Sender
305                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
306                replicationMode="pooled"
307                ackTimeout="15000"/>
308
309            < Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
310                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
311
312            < Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
313                      tempDir="/tmp/war-temp/"
314                      deployDir="/tmp/war-deploy/"
315                      watchDir="/tmp/war-listen/"
316                      watchEnabled="false"/>
317        < /Cluster>
318        -->
319
320
321
322        < !-- Normally, users must authenticate themselves to each web app
323             individually.  Uncomment the following entry if you would like
324             a user to be authenticated the first time they encounter a
325             resource protected by a security constraint, and then have that
326             user identity maintained across *all* web applications contained
327             in this virtual host. -->
328        < !--
329        < Valve className="org.apache.catalina.authenticator.SingleSignOn" />
330        -->
331
332        < !-- Access log processes all requests for this virtual host.  By
333             default, log files are created in the "logs" directory relative to
334             $CATALINA_HOME.  If you wish, you can specify a different
335             directory with the "directory" attribute.  Specify either a relative
336             (to $CATALINA_HOME) or absolute path to the desired directory.
337        -->
338        < !--
339        < Valve className="org.apache.catalina.valves.AccessLogValve"
340                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
341                 pattern="common" resolveHosts="false"/>
342        -->
343
344        < !-- Access log processes all requests for this virtual host.  By
345             default, log files are created in the "logs" directory relative to
346             $CATALINA_HOME.  If you wish, you can specify a different
347             directory with the "directory" attribute.  Specify either a relative
348             (to $CATALINA_HOME) or absolute path to the desired directory.
349             This access log implementation is optimized for maximum performance,
350             but is hardcoded to support only the "common" and "combined" patterns.
351        -->
352        < !--
353        < Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
354                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
355                 pattern="common" resolveHosts="false"/>
356        -->
357    < Context docBase="D:\WORKS\EShop\EWebShop" path="/" reloadable="true"
                workDir="D:\WORKS\EShop\Tomcat\work\EWebShop">
358    < /Context>
359      < /Host>   
360< Host name="yvor.vicp.net" appBase="webapps"unpackWARs="true" autoDeploy="true"xmlValidation="false"
                xmlNamespaceAware="false">
361    < Context docBase="D:\WORKS\YCOE\ycoe" path="/" reloadable="true" workDir="D:\WORKS\YCOE\Tomcat\work\ycoe">
362    < /Context>
363      < /Host>
364    < /Engine>
365  < /Service>
366< /Server>
367
368
  可以看到,这里修改了
  81行修改了两个参数值:< Connector port="80" maxHttpHeaderSize="8192"
                maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                enableLookups="false" redirectPort="8443" acceptCount="100"
                connectionTimeout="20000" disableUploadTimeout="true"  URIEncoding="GB2312"/>
          修改port是修改Tomcat的服务端口,默认为8080,URIEncoding改为GB2312是为了使用中文路径
    但不建议使用.

  125行:< Engine name="Catalina" defaultHost="ycoe.vicp.net">在下面配置的< Host/>中,必须有一个Host和这里的defaultHost的值相同!

        192行:< Host name="ycoe.vicp.net" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

  然后再添加360行开始的< Host>元素:< Host name="yvor.vicp.net" appBase="webapps"unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
    < Context docBase="D:\WORKS\YCOE\ycoe" path="/" reloadable="true"
            workDir="D:\WORKS\YCOE\Tomcat\work\ycoe">< /Context>
< /Host>
  这里是设置我们的第二个虚拟网站的域名.
  注:< Context/>里面的内容并不是我们实际应用的,我们可以通过另一种比较方便而且容易修改的方式来设置这些参数.下面我们来做这方面的配置:
  1.在%CATALINA_HOME %\conf\Catalina目录下创建ycoe.vicp.net和yvor.vicp.net两个文件夹.
  2.在这两个文件夹里面创建ROOT.xml文件(要以ROOT.xml为名称,否则虽然不会出错,但不能用http://ycoe.vicp.net或http://yvor.vicp.net直接访问)
  3.ROOT.xml的内容如下:
< ?xml version='1.0' encoding='utf-8'?>
< Context docBase="D:\WORKS\EShop\EWebShop" path="/" reloadable="true"
workDir="D:\WORKS\EShop\Tomcat\work\EWebShop">
< /Context>

  根据自己的实际情况,设置这里的docBase 和workDir的路径.docBase是说明文档的路径,workDir是网站程序的路径,如果用相对路径,则是在%CATALINA_HOME %\webapp目录下,path是访问的路径


[ 发表评论 ] 字体[  ] [ 打印 ] [ 进入博客 ] [ 进入论坛 ]  [ 推荐给朋友 ]
  相关文章
· Java入门:Java语言怎样调用外部应用程序 (03-05) · J2EE综合--浅析Java程序员的存储过程 (03-05)
· HashMap中的对象根据成员进行自定义排序 (03-05) · 进阶:怎样使用AJAX进行WEB应用程序开发 (03-05)
· 如何正确的选择适合自己的WEB报表工具 (03-05) · 开发工具:程序员应如何提高系统分析能力 (03-05)
· 程序人生-- 一些编程初学者的良言警句 (03-05) · JSP/Servlet/JSF:Servlet/JSP配置详解 (03-05)
· Java语言深入--关于Java语言的内存泄漏 (03-05) · 设计及设计模式:对于模式的“十大误解” (03-05)
  客户需求反馈表
* 姓  名:
更多资料  了解方案  认识厂商
* 单位名称:
* 联系电话:
* 电子邮件:
  赛迪推荐  
  手机·资费 ·新品·导购·评测·手机资费·宽带
手机搜索  诺基亚 N73 MOTO Z6
  IT产品 ·笔记本·台式机·服务器·打印·投影
IT产品搜索 
  IT技术 ·开发·网管·安全·数据库·操作系统
  信息化 ·热点·专题·访谈·周刊·方案案例
· 网站建设市场重新洗牌 一卡通引领革命潮流
· 北京加快信息化建设 医保一卡通年底前启动
· ERP案例分析 SaaS带来冲击 IT服务商面临挑战
· 通方期货CRM解决方案 房地产行业CRM解决方案
  IT博客 ·曾剑秋·项立刚·Java学习·网管
  IT技术论坛 ·开发·网管·安全·数据库·系统