我已经检查了几乎所有关于 stackoverflow 的相关文章,但我无法解决我的问题。
这是代码:web.xml:
<display-name>Spring3MVC</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>/</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
弹簧servlet.xml:
<context:component-scan base-package="com.mycompany.elso" />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
我的控制器:
public class myController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
网页/index.jsp:
<html>
<head>
<title>Spring 3.0 MVC Series</title>
</head>
<body>
<a href="hello.html">Say Hello</a>
</body>
</html>
网页/WEB-INF/jsp/hello.jsp:
<html>
<head>
<title>Spring 3.0 MVC Series: Hello World - ViralPatel.net</title>
</head>
<body>
${message}
</body>
</html>
因此,当我启动应用程序时,index.jsp 已正确加载,但是当我单击 href 导航到 hello.jsp 时,出现 404 错误,服务器日志显示:
No mapping found for HTTP request with URI [/Elso/hello.html] in DispatcherServlet with name 'spring'
我已经检查了几十篇这样的文章,但我就是找不到错误,有人知道它可能是什么吗?