请求Spring MVC项目资源出现HTTP Status 404错误求助
Hey there, let's work through this 404 error you're facing when accessing http://localhost:8090/FirstSpringMVCProject/welcome.html. Tomcat is telling you the requested resource isn't available, so let's break down the most likely fixes based on what you've shared so far.
1. Validate Your Controller Configuration
Your HelloController.java snippet was cut off, so let's start with the basics here:
- Make sure your controller class has the
@Controllerannotation (critical for Spring to recognize it) - Verify your handler method maps to the correct URL pattern. If you're extending
AbstractController, your code should look something like this:
package com.amarnath.spring.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; @Controller public class HelloController extends AbstractController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { // "welcome" here should match your view file name (without suffix) ModelAndView modelAndView = new ModelAndView("welcome"); modelAndView.addObject("message", "Hello from Spring MVC!"); return modelAndView; } }
- If you're using XML config, ensure the controller is registered in
dispatcher-servlet.xml:
<bean name="/welcome.html" class="com.amarnath.spring.controller.HelloController" />
- For annotation-based setups, enable component scanning to let Spring find your controller:
<context:component-scan base-package="com.amarnath.spring.controller" />
2. Check Your View Resolver Setup
Spring needs to know where to locate your view files (like JSPs). Confirm your dispatcher-servlet.xml has a properly configured view resolver:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <!-- Path to your view files --> <property name="suffix" value=".jsp" /> <!-- File extension of your views --> </bean>
With this setup, your welcome.jsp file should live at /WEB-INF/views/welcome.jsp to be found correctly.
3. Verify the Deployment Context Path
Double-check that your project is deployed with the context path FirstSpringMVCProject. You can confirm this via Tomcat's manager app, or check your IDE's deployment settings—sometimes IDEs use lowercase project names or no context path by default, which would break your URL.
4. Ensure Dispatcher Servlet Maps to .html Requests
In your web.xml, make sure the dispatcher servlet is configured to handle .html requests so they get routed to Spring:
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
5. Rule Out Typos
It's easy to overlook small typos—double-check:
- The URL is exactly
http://localhost:8090/FirstSpringMVCProject/welcome.html(no extra slashes, correct capitalization) - Your view file name matches the
ModelAndViewvalue (e.g.,welcome.jspnotWelcome.jspon case-sensitive systems) - If using
@RequestMapping, the path matches the URL (e.g.,@RequestMapping("/welcome.html")or@RequestMapping("/welcome")if the suffix is handled by the view resolver)
If you can share the full HelloController code and your full configuration files (dispatcher-servlet.xml, web.xml), we can narrow this down even further!
内容的提问来源于stack exchange,提问作者Amarnath Kumar Sah

