Premise: If
1, there is an application: Hello2, the application storage path:D:\apache-tomcat-5.5.17 \webapps\hello
The protagonist of Scourge in Tomcat's server.xml configuration file
<path= "" reloadable= "true" docBase= "Hello" />
(The purpose of this is to set the Hello app as the root and access the app directly when the IP is accessed)
Add a servlet app Hello
There is a servlet under hello (for the system to perform some initialization at startup), and there is an init () method in the servlet that currently only prints the "Hello word" string in the method;
The Web. Xml section of the Hello app has the following configuration information:
<servlet> <Servlet-name>HelloServlet</Servlet-name> <Servlet-class>HelloServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet>
Problem:
When you start TOMCAT5, the console window prints two lines of "Hello word" strings?
Cause of the problem:
Workaround:
Method 1, do not put the Hello application in the default WebApp directory of Tomat, move it out, and then modify the value of Docbase in Server.xml to the absolute path of Hello application in the new location can be;
The first method:
In the Conf directory in Tomcat, in Server.xml,<host/><Path = "/hello" docBase= "D:eclipse3.2.2forwebtoolsworkspacehellowebroot" Debug = "0" privileged= "true"></Context >
For the context node properties, you can see the relevant documentation in detail.
The second method:
The third method:
<path= "/hello" docBase= "D: Eclipse3.2.2forwebtoolsworkspacehellowebroot " debug=" 0 " privileged=" true " ></Context>
The 3rd method of
has the advantage of defining an alias. The server-side run project name is path, and the externally accessed URL uses the XML file name. This method is very convenient to hide the name of the project, some project names are fixed can not be replaced, but external access when you want to change a path, very effective.
2nd, 3 There are advantages, you can define some personality configuration, such as the configuration of the data source.
There is also a detailed
Here are the three ways that Tomcat deployment publishes JSP applications
1, drop directly into the WebApps directory
Tomcat's WebApps directory is the default app directory for Tomcat, which loads all applications in this directory when the server is started. You can also package a JSP program into a war package and place it in a directory where the server automatically unlocks the war package and generates a folder with the same name in this directory. A war package is a jar package with an attribute format that compresses all the contents of a Web program. Specifically how to package, you can use the IDE environment of many development tools, such as Eclipse, NetBeans, ant, JBuilder, etc. You can also use the cmd command: JAR-CVF applicationname.war package.*;
can even be packaged in program execution:
Try { = System.getproperty ("Java.home"); =strjavahome.substring (0,strjavahome.lastindexof (\)) + "\\bin\\"; Runtime.getruntime (). EXEC ("cmd/c start" +strjavahome+ "Jar CVF catch(Exception e) {
WebApps This default application directory can also be changed. Open the Server.xml file under Tomcat's Conf directory to find the following:
<name= "localhost" debug= "0" appBase= "WebApps" unpackwars= "true" autodeloy= "true" xmlvalidation= " Falase " xmlnamespaceaware=" false ">
2. Specify in Server.xml
In the Tomcat configuration file, a Web application is a specific context that can be deployed by deploying a JSP application in a new context in Server.xml. Open the Server.xml file and create a context within the host tag, as follows.
<path= "/myapp" reloadable= "true" docBase= "D:\ MyApp " workdir=" D:\myapp\work"/>
Where path is the virtual path, Docbase is the physical path to the JSP application, and Workdir is the working directory of the application, which stores the files that are generated for this application.
3. Create a context file
In both of these ways, the Web application is loaded by the server and generates an XML file in the Tomcat Conf\catalina\localhost directory with the following content:
<path= "/admin" docBase= "${catalina.home}/server/webapps/admin" Debug= "0" privileged= "true"></Context >
As can be seen, the file describes an application's context information, its content and server.xml in the context information format is consistent, the file name is the virtual directory name. You can directly create an XML file that is placed in the Tomcat Conf\catalina\localhost directory. Examples are as follows:
Note: Deleting a web App also deletes the corresponding context in the corresponding folder or Server.xml under WebApps, and the Tomcat conf
The corresponding XML file is deleted under the \catalina\localhost directory. Otherwise tomcat will still be configured to load ...
Service. XML configuration Absolute Path (Linux)
<Hostname= "localhost"AppBase= "WebApps"Unpackwars= "true"Autodeploy= "true"> <!--Singlesignon valve, share authentication between Web applications documentation at:/docs/config/valve.ht ML - <!--<valve classname= "Org.apache.catalina.authenticator.SingleSignOn"/> - <!--Access Log processes all example. Documentation at:/docs/config/valve.html note:the pattern used are equivalent to using pattern= "common" - <ValveClassName= "Org.apache.catalina.valves.AccessLogValve"Directory= "Logs"prefix= "Localhost_access_log."suffix= ". txt"pattern= "%h%l%u%t "%r"%s%b" /> <ContextPath=""DocBase= "/var/wwwroot/xxx"Debug= "0"reloadable= "true"Crosscontext= "true"/> </Host>
tomcat-Introduction and resolution of two repeated loading issues when publishing a project