Tomcat demining notes
1. Scene
Eclipse publishes a web application to Tomcat. By default, accessing the project requires the project name http://localhost :8080/myapp/。
Now it needs to be changed to this way http://localhost 。
Modify Tomcat’s server.xml File, add the following configuration<Context path="" docBase="myapp" reloadable="false"/>
After modification, the host part is as follows:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="myapp" reloadable="false"/>
</Host>
At this point, every time you start Tomcat to observe the log, you will find that the application has been loaded twice. Why?
2. Cause of the problem
For the problem caused by virtual directory, we configured appbase = webapps in the host tag, and Tomcat loaded the application once. Docbase is configured once in, and Tomcat loads the application again.
3. Solutions
Set appbase = webapps to appbase = and docbase = myapp to docbase = webapps / myapp. The configuration is as follows:
<Host name="localhost" appBase=""
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="webapps/myapp" reloadable="false"/>
</Host>
Note: if the links or pictures in your project are all absolute paths, then the absolute path with the project name cannot be used.