没有尾部斜杠,无法将Spring MVC中的POST请求方法映射到应用程序的根目录

问题描述

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

解决方法

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将其与斜杠一起转发。
。然后,我得到以下信息:

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