求助:XAMPP环境下Tomcat无法访问localhost/examples等路径的解决办法
Hey there, let's troubleshoot this Tomcat issue step by step since you're using XAMPP. It's odd that only the root localhost works but the /examples and /doc contexts are throwing errors—let's break this down into actionable checks:
- Open your XAMPP Control Panel and verify the Tomcat module shows a green "Running" status. If it's stopped, start it and watch the console tab for immediate error messages.
- Sometimes Tomcat can hang during initialization even if the control panel says it's running. Try stopping it, waiting 10 seconds, then restarting to rule out a partial startup.
Let's check the configs that control how Tomcat loads web applications:
a. server.xml (Located in XAMPP\tomcat\conf)
- Locate the
<Host>element (usually around lines 160-180). Ensure it has theappBase="webapps"attribute—this tells Tomcat where to pull its pre-built apps likeexamplesanddocsfrom. - If you added custom
<Context>entries for/examplesor/docearlier, comment them out temporarily to test if they're causing conflicts. A valid Host block should look something like this:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- Default access log configuration --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
b. web.xml (Located in XAMPP\tomcat\conf)
- Make sure the
defaultservlet is properly configured—this handles serving static content and context roots. Look for this block:
<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> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
- The key here is that the servlet and its mapping exist—adjusting the
listingsvalue won't break access, but missing entries will.
- Navigate to
XAMPP\tomcat\webapps—you should see folders namedexamples,docs,ROOT, etc.- If
examplesordocsare missing, your Tomcat installation might be corrupted. Restore these folders from a fresh Tomcat download (XAMPP includes them by default). - On Windows, ensure the
webappsfolder isn't marked as "Read-only". On macOS/Linux, runchmod -R 755 XAMPP/tomcat/webappsto set proper read/write/execute permissions for Tomcat.
- If
Logs are your best tool here—they'll tell you exactly what's failing:
- Go to
XAMPP\tomcat\logsand open the latestlocalhost.logorlocalhost.errfile. - Look for exceptions like
ClassNotFoundException,FileNotFoundException, orContext initialization failed—these point directly to issues like missing JAR files or broken configs. - Also check
catalina.outfor startup errors—it logs Tomcat's entire initialization process, so you might catch a failure that didn't show up in the control panel.
Corrupted cached data can break app loading:
- Stop Tomcat first.
- Delete all contents in
XAMPP\tomcat\work(Tomcat will rebuild this folder automatically when it restarts). - Restart Tomcat and try accessing
/examplesagain.
Other applications might be using Tomcat's default ports (8080, 8005, 8009):
- In XAMPP Control Panel, click "Config" next to Tomcat, then open
server.xml. - Check these port entries:
<Connector port="8080" ...>(HTTP port)<Server port="8005" ...>(Shutdown port)<Connector port="8009" ...>(AJP port)
- If any port is in use (e.g., by IIS, Skype, or another server), change it to an unused port (like 8081 for HTTP) and restart Tomcat.
If none of the above fixes the issue, your Tomcat installation in XAMPP might be irreparably corrupted:
- Stop Tomcat in the XAMPP Control Panel.
- Uninstall the Tomcat module via XAMPP's "Manage Modules" option.
- Reinstall Tomcat through XAMPP's module installer.
- Test with a fresh install first, then restore your custom servlet configurations if needed.
After each step, test accessing localhost/examples and localhost:8080/doc again. If you find a specific error in the logs, feel free to share it—I can help narrow it down further!
内容的提问来源于stack exchange,提问作者Sarathi Shah

