This article mainly summarizes three methods for deploying and releasing JSP applications in Tomcat.
1. directly put it in the Webapps directory
The Webapps directory of Tomcat is the default application directory of Tomcat. When the server starts, all applications under this directory will be loaded. You can also package the JSP program into a war package and place it in the directory. The server will automatically unbind the war package and generate a folder with the same name under this directory. A war package is a jar package with a special format. It compresses all the content of a Web program. You can use IDE environments of many development tools, such as Eclipse, NetBeans, ant, and JBuilder. You can also run the cmd command: jar-cvf applicationname. war package .*;
You can even package in program execution:
Try {
String strjavahome = system. getproperty ("java. home ");
Strjavahome = strjavahome. substring (0, strjavahome. lastindexof (\) + "\ bin \\";
Runtime.getruntime(cmd.exe c ("cmd/c start" + strjavahome + "jar cvf hello. war c: \ tomcat5.0 \ webapps \ root \\*");
}
Catch (exception e) {system. out. println (e );}
The default application directory webapps can also be changed. Open the server. xml file in the conf directory of Tomcat and find the following content:
<Host name = "localhost" debug = "0" appBase = "webapps" unpackWARs = "true" autoDeloy = "true" xmlValidation = "falase" xmlNamespaceAware = "false">
2. Specify
In the Tomcat configuration file, a Web application is a specific Context. You can deploy a JSP application in the new Context in server. xml. Open the server. xml file and create a Context in the Host tag. The content is as follows.
<Context path = "/myapp" reloadable = "true" docBase = "D: \ myapp" workDir = "D: \ myapp \ work"/>
Here, path is the virtual path, docBase is the physical path of the JSP application, workDir is the working directory of the application, and the files generated for running the application are stored.
3. Create a Context File
After the Web application is loaded by the server, an XML file is generated in the conf \ catalina \ localhost directory of Tomcat. The content of the XML file is as follows:
<Context path = "/admin" docBase = "$ {catalina. home}/server/webapps/admin" debug = "0" privileged = "true"> </Context>
It can be seen that the Context information of an application is described in the file. Its content is consistent with the Context information format in server. xml, and the file name is the virtual directory name. You can directly create an xml file and place it in the conf \ catalina \ localhost directory of Tomcat. Example:
Note: To delete a Web application, you also need to delete the corresponding Context in the server. xml folder under webapps, and set the conf
Delete the xml file in the \ catalina \ localhost directory. Otherwise, Tomcat will still be loaded with the shore configuration...