首页新闻找找看学习计划

HiddenHttpMethodFilter问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2017-12-29 12:01
 我配置了HttpMethodFilter,但是put和delete请求不能跳转到目标方法,也不能跳转到jsp页面。报错信息的意思是:jsp只支持post和get请求,很无奈。
   
相关配置如下:
 
web.xml:
       
<!-- 配置 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>

    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <!-- 配置 DispatcherServlet 的一个初始化参数: 配置 SpringMVC 配置文件的位置和名称 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

 

 

  springmvc.xml:

      

    <context:component-scan base-package="cn.ccsu.springmvc.handler"></context:component-scan>
        
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

 

 

目标方法:

  

@RequestMapping(value = "/TestRestDelete/{id}", method = RequestMethod.DELETE)
    public String testRestDelete(@PathVariable("id") Integer id) {

        System.out.println("testRestDelete  id:" + id);
        return "success";
    }

    @RequestMapping(value = "/TestRest/{id}", method = RequestMethod.POST)
    public String testRestPost(@PathVariable("id") Integer id) {

        System.out.println("testRestPost  id:" + id);
        return "success";
    }

    @RequestMapping(value = "/TestRestPut/{id}", method = RequestMethod.PUT)
    public String testRestPut(@PathVariable("id") Integer id) {

        System.out.println("testRestPut  id:" + id);
        return "success";
    }

 

    html表单:

     

<form action="springmvc/TestRestPut/120" method="post">
        <input type="hidden" name="_method" value="PUT" /> <input
            type="submit" value="Rest Put" />
    </form>

 

  

  

rm_rf的主页 rm_rf | 初学一级 | 园豆:6
提问于:2017-10-05 17:33
< >
分享
所有回答(1)
0

哥们,我也是这样,web.xml html都写对了,可就是405,不接受POST请求啊。

Eysa | 园豆:68 (初学一级) | 2018-10-27 15:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册