After TOMCAT is installed, just copy your Web project to%tomcat_home%webapp and it's ready to use!! In fact, there is a way to set up a virtual directory, that is, to map the project directory into Tomcat. This saves time and makes it easy for developers to deploy without duplication.
Here's how:
1, find%tomcat_home%\conf\catalina\localhost,catalina\localhost directory if there is a manual creation, in the directory to create an XML file, the file name can not be arbitrarily defined, if you define as test, Then the access path is http://localhost:8080/test/....
<context reloadable= "true" debug= "0" docbase= "E:\workspace\test\bin" workdir= "E:\workspace\test\work" Crosscontext= "true" >
</Context>
You do not need to configure path
Docbase is the actual path, here generally write an absolute disk path, of course, you can write a relative path, relative path is relative to the Tomcat installation directory of the WebApps directory, usually set up the virtual directory is the purpose of the Tomcat installation and the preservation of the project, so it is recommended that you Use the absolute path of the disk, and this disk path is occasionally in the Tomcat installation directory. Workdir is a tomcat run is a compiled file for JSP files, this file is best also separate.
Docbase is the Webroot level directory for the project folder, such as:
D:\workspace\project\releasedir\FinanceStock
Workdir refers to the Tomcat parsing JSP into a Java file, and compiled into a class folder, set in the project folder, you can avoid porting to other places first read the JSP file needs to be re-parsed
Tomcat 6 does not need to set the debug= "0" property, otherwise the following warning is available:
Setting property ' Debug ' to ' 0 ' didn't not find a matching property
Today I did a test, feeling that only if Docbase is under the Tomcat installation directory to start properly
2, if there is a 404 error in the test, if the previous configuration is not wrong, it may be in the%tomcat_home%\conf\web.xml file to display the virtual path directory to prohibit, at this time can be found in the Web. xml file
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Change the value of listings to true, then restart Tomcat, and at the input URL, the test succeeds!
3, if the project is developed and ready for deployment on the server, remember to change the value of the parameter listings in the Web. xml file in the third step to false so that you can avoid presenting the project's deployment path to the consumer!
Specific as follows:
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
4, access to more than one machine file problem:
When there are too many files, it is necessary to cross-catalog or cross-disk, this time need to use the virtual directory, but Tomcat can not directly cross the context of forward.
For example:
Virtual directory Data1 mapped with context configuration, file 123.txt in directory
If you want to forward directly to "/data1/123.txt" is not possible, you will be prompted 404 cannot find the file.
Then you need to apply the Tomcat virtual directory mapping flexibly:
In the D:\Tomcat\conf\Catalina\test directory (test is the domain name in the server.xml configuration file), add an XML file (test to create), After creation, add this kind of XML file (named Data1.xml here):
<context docbase= "\\IP\data1" reloadable= "false" crosscontext= "true"/>
and modify the context in Server.xml to allow crosscontext= "true".
Then you can access the files on the other machine in the project (of course, this machine needs to share the files that are accessed). For example:
Again, the issue of permissions, the shared files do not want to give anyone access, you need to set up sharing permissions, then you need to configure the permissions of Tomcat:
1. Set up the Tomcat account and password on the shared machine and join the share permissions.
2. Then on the server where Tomcat is placed, set the same Tomcat account and password.
3. Configure the login account and password on the Tomcat service.
Tomcat Server.xml Docbase Workdir