没有尾部斜杠,无法将Spring MVC中的POST请求方法映射到应用程序的根目录. [英] Mapping a POST request method in Spring MVC to the root of the application does not work without a trailing slash.

查看:256
本文介绍了没有尾部斜杠,无法将Spring MVC中的POST请求方法映射到应用程序的根目录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

控制器方法签名:

@RequestMapping(value = {"","/"}, method = RequestMethod.POST)
public ModelAndView index(Model model, @RequestParam("someParam") String someParam)

问题是,当我在末尾打上斜杠时,效果很好,但是当我在末尾打上斜杠时,JBoss(或浏览器)接收到请求,并通过GET将其转发.末尾的斜线.然后,我得到以下信息:

The problem is that when I hit the root with the trailing slash it works fine, but when I hit the root with no trailing slash, then JBoss (or the browser) is picking up the request, and forwarding it via GET with the trailing slash. I then get the following:

HTTP状态405-请求方法'GET'不支持

HTTP Status 405 - Request method 'GET' not supported

推荐答案

事实证明,这是有关Apache和Tomcat上下文配置方式的问题.以上工作正常.

It turns out this was an issue with how Apache and the context for Tomcat was configured. The above works just fine.

这篇关于没有尾部斜杠,无法将Spring MVC中的POST请求方法映射到应用程序的根目录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆