Tomcat服务异常:访问localhost:1996/cart.html出现HTTP ERROR 404如何解决?
Hey, let’s work through this 404 issue—since your setup worked before, it’s almost certainly a small misconfiguration or file placement hiccup that popped up recently. Here’s how to troubleshoot step by step:
Double-check your file’s location
Tomcat serves web content from thewebapps/[your-webapp-folder]/directory. Make surecart.htmlis directly inside this folder (not buried in a subfolder unless your URL includes that subpath). If you’re using the default app, it needs to be inwebapps/ROOT/—if you renamed your app folder, adjust your URL to include the folder name (e.g.,http://localhost:1996/myapp/cart.html). Also confirm you didn’t accidentally delete or move the file lately.Verify Tomcat’s port and context path
- Open
conf/server.xmlin your Tomcat install, find the<Connector>tag, and ensure theportattribute is set to1996. If you changed this port recently, you must restart Tomcat for the change to take effect. - If your web app isn’t the default ROOT, your URL needs to include the app’s folder name. For example, if your app is in
webapps/shop/, the correct URL ishttp://localhost:1996/shop/cart.html.
- Open
Check Tomcat logs and restart the server
- Head to Tomcat’s
logs/folder and opencatalina.outorlocalhost.log. Look for errors related to deployment, file permissions, or missing resources—for example, if Tomcat can’t readcart.htmldue to permission issues, that’ll throw a 404. - Sometimes temporary deployment glitches cause files to go unrecognized. Stop Tomcat completely, wait 10 seconds, then start it again to clear any cached deployment issues.
- Head to Tomcat’s
Clear browser cache and check URL spelling
- Browsers often cache old 404 pages. Clear your cache (use Ctrl+Shift+Delete on most browsers) and try the URL again.
- Tomcat is case-sensitive on most operating systems, so double-check the URL: make sure it’s
http://localhost:1996/cart.html(no typos, extra slashes, or capital letters likeCart.html).
If none of these fix it, you can quickly check your web.xml file to ensure there’s no filter or servlet mapping that’s accidentally blocking access to cart.html—but since it worked before, this is less likely.
内容的提问来源于stack exchange,提问作者sree_val

