控制器
@Controller
public class Tester {
@RequestMapping(value="testPost", method = RequestMethod.POST)
public ModelAndView testPost(){
ModelAndView _mv = new ModelAndView();
_mv.setViewName("shared/post");
return _mv;
}
}
HTML
<form action="testPost" method="post">
<input type="submit" value="Submit" />
</form>
Web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>iCubeHRS</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>site_mesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>site_mesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
问题
一旦将“method”属性设置为“POST”,当你点击提交按钮时,它总是变成405 - 不支持请求方法'POST',如果从控制器中删除方法属性,以及从HTML中删除方法=“post”,它有效,有人知道如何解决这个问题吗?
更新
我想我找到了问题,这个问题是由 sitemesh3 引起的,在我从 web.xml 中删除了 sitemesh3 功能后,POST 工作正常,但我不知道如何解决它。