SpringMVC表单中post请求转换为put或delete请求

  1.在web.xml文件中配置

   <!-- HiddenHttpMethodFilter过滤器可以将POST请求转化为put请求和delete请求! -->
    <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>

  2.在表单域中

      需要携带一个name值为_method,value值为put或者delete的参数,如下所示:

 <form action="${pageContext.request.contextPath }/order/1" method="post">
    <input type="hidden" name="_method" value="put"/>
    <input type="submit" value="Submit"/>
   </form>
   <form action="${pageContext.request.contextPath }/order/1" method="post">
    <input type="hidden" name="_method" value="delete"/>
    <input type="submit" value="Submit"/>
   </form>   
上一篇:Django基础和基本使用


下一篇:MongoDB安装与故障