You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地正常的Java Web项目部署至生产服务器后出现404错误求助

Troubleshooting the "Not Found" Error for Your Servlet Deployment

Let’s break down what might be going wrong here and fix it step by step:

1. Fix the Critical Typo in Your .htaccess File

First off, there’s a spelling mistake in your .htaccess that’s almost certainly throwing things off. You wrote:

SetHandler Jakar-servlet
SetEnv JK_WORKER_NAME ajp13

Change Jakar-servlet to jakarta-servlet (correct spelling and standard lowercase convention):

SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13

Also, double-check that your server’s Apache setup has mod_jk enabled, and that the JK_WORKER_NAME matches the worker defined in your workers.properties file (it’s usually ajp13 by default, but worth confirming).

2. Verify Your Deployment Directory Structure

When you unpacked your WAR file into public_html, make sure the folder structure follows this pattern:

public_html/
└── Test/
    ├── WEB-INF/
    │   ├── classes/
    │   │   └── com/
    │   │       └── test/
    │   │           └── Test.class
    │   ├── lib/
    │   └── web.xml (if you’re using one)
    └── [any static files your app uses]

If the unpacked content is directly in public_html instead of a Test subfolder, your URL should drop the /Test/ part and become http:///~(myusername)/HelloWorld.

3. Confirm Context Path and Servlet Mapping

Your servlet uses @WebServlet("/HelloWorld"), which maps it to the root of your application’s context. So:

  • If your app’s context path is Test (the folder name in public_html), the URL you tried (http:///~(myusername)/Test/HelloWorld) is correct—but only if the server recognizes Test as a valid web application context.
  • Some shared hosting environments require deploying apps to a specific directory (like a webapps folder under your user account) instead of public_html. Check your host’s guidelines to confirm the right deployment path.

4. Check File Permissions

Make sure the unpacked files and directories have the right permissions so the Tomcat/Apache process can read them:

  • The WEB-INF directory and its contents (classes, lib) should have read permissions for the server user (typically www-data or apache).
  • Skip overly permissive permissions like 777, but ensure the server can access all necessary files.

5. Dig Into Server Logs for Clues

This is one of the most useful steps—check these logs to get specific error details:

  • Tomcat’s localhost.log and localhost_access_log.* (usually located in tomcat/logs under your user directory)
  • Apache’s error_log (found in apache/logs or a similar location)
    These logs will tell you if the server can’t locate the servlet, if there’s an AJP connection failure, or if the context path is misconfigured.

6. Ensure Tomcat’s AJP Connector is Enabled

Open your Tomcat’s server.xml file and confirm the AJP connector isn’t commented out:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

If it’s commented, uncomment it and restart Tomcat. Without this connector, Apache can’t forward requests to Tomcat via AJP.


内容的提问来源于stack exchange,提问作者Jack G.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:40:40