【发布时间】:2014-04-24 02:15:32
【问题描述】:
我正在使用请求映射注解编写一个 Spring 应用程序。 http://localhost:8080/SpringMVC/hello 给出 404(请求的资源不可用)。从服务器记录数据`在 DispatcherServlet 中找不到带有 URI [/SpringMVC/WEB-INF/jsp/helloView.jsp] 的 HTTP 请求的映射,名称为“dispatcher”。
有人可以帮忙吗。
项目结构
@Controller
@RequestMapping(value="/hello")
public class HelloController
{
@RequestMapping(method=RequestMethod.GET)
public ModelAndView sayHello()
{
ModelAndView view=new ModelAndView("helloView","HelloMessage", "Welcome");
return view;
}
}
helloView.jsp
<html>
<head>
<title>Spring Application</title>
</head>
<body>
<h2>${HelloMessage}</h2>
</body>
</html>
web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
调度程序-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="controller" />
<mvc:annotation-driven />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
【问题讨论】:
-
控制台中有任何日志消息?
标签: spring spring-mvc