【问题标题】:Sitemesh3 POST failSitemesh3 POST 失败
【发布时间】:2013-04-01 22:51:59
【问题描述】:

转发SpringMVC 3 405 - Request method 'POST' not supported

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的源代码,但没有发现任何有价值的东西。

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

【问题讨论】:

    标签: spring sitemesh


    【解决方案1】:

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

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

    &lt;mvc:resources /&gt; 不接受装饰器文件的 post 请求,因为 sitemesh 试图使用 Post 请求访问它。

    我更改了我的装饰器文件的映射,以确保它是静态的并响应 POST 和 GET 请求。更多细节在这里Spring: not accept POST request under mvc:resources? how to fix that

    我使用的代码是

    <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>
    

    【讨论】:

      猜你喜欢
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2013-02-08
      • 2016-11-17
      • 2013-03-21
      • 1970-01-01
      相关资源
      最近更新 更多