springMVC报错Request method 'PUT' not supported 错误啊?求解

qq_37879809 2017-07-18 10:54:01


web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<!-- 配置 org.springframework.web.filter.HiddenHttpMethodFilter: 可以把 POST
请求转为 DELETE 或 POST 请求 -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- 配置 DispatcherServlet -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置 DispatcherServlet 的一个初始化参数: 配置 SpringMVC 配置文件的位置和名称 -->
<!-- 实际上也可以不通过 contextConfigLocation 来配置 SpringMVC 的配置文件, 而使用默认的. 默认的配置文件为:
/WEB-INF/<servlet-name>-servlet.xml <init-param> <param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value> </init-param> -->
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>











@RequestMapping(value="/Hello",method=RequestMethod.GET)
@Controller
public class Hello {
private static final String SUCCESS = "success";

@RequestMapping(value = "/testRest/{id}", method = RequestMethod.PUT)
public String testRestPut(@PathVariable Integer id) {
System.out.println("testRest Put: " + id);
return SUCCESS;
}

@RequestMapping(value = "/testRest/{id}", method = RequestMethod.DELETE)
public String testRestDelete(@PathVariable Integer id) {
System.out.println("testRest Delete: " + id);
return SUCCESS;
}

@RequestMapping(value = "/testRest", method = RequestMethod.POST)
public String testRest() {
System.out.println("testRest POST");
return SUCCESS;
}

@RequestMapping(value = "/testRest/{id}", method = RequestMethod.GET)
public String testRest(@PathVariable Integer id) {
System.out.println("testRest GET: " + id);
return SUCCESS;
}


/**
* 了解: 可以使用 params 和 headers 来更加精确的映射请求. params 和 headers 支持简单的表达式.
*
* @return
*/
@RequestMapping(value="hello",method=RequestMethod.GET,
params={"name","id!=1"},headers = { "Accept-Language=zh-CN,zh;q=0.8"})
public String hello(){

System.out.println("Hello");
return SUCCESS;

}
/**
* @PathVariable 可以来映射 URL 中的占位符到目标方法的参数中.
* @param id
* @return
*/
@RequestMapping("/testPathVariable/{id}")
public String testPathVariable(@PathVariable("id") Integer id) {
System.out.println("testPathVariable: " + id);
return SUCCESS;
}



}


jspye'm
...全文
544 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_37879809 2017-07-18
  • 打赏
  • 举报
回复
jsp <form action="${pageContext.request.contextPath }/Hello/testRest/1" method="post"> <input type="hidden" name="_method" value="PUT"/> <input type="submit" value="TestRest PUT"/> </form> <br><br> <form action="Hello/testRest/1" method="post"> <input type="hidden" name="_method" value="DELETE"/> <input type="submit" value="TestRest DELETE"/> </form> <br><br> <form action="Hello/testRest" method="post"> <input type="submit" value="TestRest POST"/> </form> <br><br> <a href="Hello/testRest/1">Test Rest Get</a> <br><br>

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧