我在IntelliJ 14中创建了一个spring mvc项目,就像http://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm那样做了。但是出现了这个问题:找不到带URI的HTTP请求的映射[/test/WEB-INF/jsp/hello.jsp]在DispatcherServlet中,名称为' HelloWeb'
我用Google搜索并在stackoverflow中找到了一些链接,但它没有帮助。我的IDE是IntelliJ 14,Maven版本是3.1.1,My Spring Framework版本是4.1.6。
这是我的web.xml:
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
这是我的HelloWeb-servlet.xml:
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
这是我的控制者:
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap modelMap) {
modelMap.addAttribute("message", "Hello Spring MVC FrameWork!");
System.out.println("Hello, World!");
return "hello";
}
}
我的hello.jsp位于:/web/WEB-INF/jsp/hello.jsp,其内容为:
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
令人费解的是,我在printHello()方法中设置了一个断点,当我在浏览器中输入:http://localhost:8080/test/hello.jsp时,它进入printHello()方法并打印&#34; Hello,World !&#34;,但没有找到hello.jsp页面。
这是我在浏览器中输入http://localhost:8080/test/hello.jsp时的结果:
Hello, World!
六月 07, 2015 11:27:11 下午 org.springframework.web.servlet.PageNotFound noHandlerFound
警告: No mapping found for HTTP request with URI [/test/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'HelloWeb'
这很奇怪,任何帮助都会受到赞赏。
答案 0 :(得分:1)
您的项目结构可能有误。看两条路径:
/test/WEB-INF/jsp/hello.jsp
/web/WEB-INF/jsp/hello.jsp
他们是不同的。