控制器3用SpringMVC 405 - 请求方法 'POST' 不支持
@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 - 不支持Request方法'POST',如果从conotroller删除方法属性,并删除方法=后“从HTML,以及它的工作原理,任何人都知道如何解决这个问题?
更新
我想我找到了问题,这个问题引起sitemesh3,之后我从web.xml中删除sitemesh3功能,开机自检工作正常,但我不知道如何解决它。
所以它的工作与get方法,但不与POST方法? – 2013-04-08 16:43:10
是的,它适用于get方法,但不适用于post方法 – Shore 2013-04-09 02:22:51
web.xml中关于servlet url-pattern的代码是什么? – OQJF 2013-04-09 02:50:48