1

重新发布 SpringMVC 3 405 - 不支持请求方法“POST”

HTML

<form action="testPost" method="post"> 
    <input type="submit" value="Submit" />
</form>

动作(SpringMVC)

@RequestMapping(value="testPost", method = RequestMethod.POST)
    public String testPost(){
      return "shared/post";
}

在添加 sitemesh3 过滤器之前,这个“post”方法完美执行的提交操作,

但是一旦添加了 sitemesh3 过滤器,如果将 HTML 和操作都更改为 GET,仍然可以正常工作,但是如果我更改为 POST,则会调用该操作,但返回“405 - 不支持请求方法 'POST'”

所以我认为sitemesh3在对客户端的动作响应时改变了一些东西。我查看了sitemesh3的源代码,但没有发现任何有价值的东西。

有人可以帮忙吗?提前致谢。

4

1 回答 1

0

我不确定这是否与您的设置有关,但我遇到了同样的错误(不支持 405-post)

最初我认为它与站点网格有关。但是,当我在我的情况下对其进行更多研究时,这是因为我使用<mvc:resources /> 来提供到装饰器的静态映射。

这是<mvc:resources />因为 sitemesh 试图使用 Post 请求访问它,所以不接受装饰器文件的 post 请求。

我更改了装饰器文件的映射以确保它是静态的并响应 POST 和 GET 请求。更多细节在这里Spring:不接受 mvc:resources 下的 POST 请求?如何解决这个问题

我使用的代码是

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 <property name="urlMap">
     <map>
          <entry key="/DecTest/**" value="myResourceHandler" />
     </map>
 </property>
 <property name="order" value="100000" />       
</bean>

<bean id="myResourceHandler" name="myResourceHandler"
      class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
      <property name="locations" value="/DecTest/" />
      <property name="supportedMethods">
         <list>
            <value>GET</value>
            <value>HEAD</value>
            <value>POST</value>
         </list>
     </property>
     <!-- cacheSeconds: maybe you should set it to zero because of the posts-->
</bean>
于 2013-09-02T21:32:10.290 回答