Spring mvc Spring3.1RESTMVC示例
我试图用Spring3.1REST控制器实现一个简单的示例。问题是,由于某种原因,我找不到用于请求的资源。我做错了什么? 我正在使用Tomcat7.0。 以下是我得到的: web.xmlSpring mvc Spring3.1RESTMVC示例,spring-mvc,Spring Mvc,我试图用Spring3.1REST控制器实现一个简单的示例。问题是,由于某种原因,我找不到用于请求的资源。我做错了什么? 我正在使用Tomcat7.0。 以下是我得到的: web.xml <?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/mvc/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
还有my list.jsp:
<html>
<body>
<h1>Spring 3 MVC REST example</h1>
<h3>Movie : ${movie} , DI message : ${message}</h3>
</body>
</html>
Spring3MVC REST示例
电影:${Movie},DI消息:${message}
您提出的请求看起来像什么?如果有帮助,下面是我博客上的一个操作示例:。检查客户请求,它可能会帮助您找到问题所在。。。
package my.spring31.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/movie")
public class TestController {
//DI via Spring
String message;
@RequestMapping(value="/{name}", method = RequestMethod.GET)
public String getMovie(@PathVariable String name, ModelMap model) {
model.addAttribute("movie", name);
model.addAttribute("message", this.message);
//return to jsp page, configured in mvc-dispatcher-servlet.xml, view resolver
return "list";
}
public void setMessage(String message) {
this.message = message;
}
}
<html>
<body>
<h1>Spring 3 MVC REST example</h1>
<h3>Movie : ${movie} , DI message : ${message}</h3>
</body>
</html>