2

Controller

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

Question

Once set "method" attribute to "POST", when you hit submit button, it always turn into 405 - Request method 'POST' not supported, if delete method attribute from conotroller, and delete method="post" from HTML as well, it works, anyone know how to solve this problem?

Update

I think I found the problem, this issue caused by sitemesh3, after i removed sitemesh3 features from web.xml, POST works fine, but I don't know how to solve it.

Shore
  • 123
  • 2
  • 10

2 Answers2

1

I am not sure if this is relevant to your setup but I had the same error (405-post not supported)

Initially I thought it was sitemesh related. However when I looked into it a bit more in my case it was because I was using <mvc:resources /> to provide a static mapping to the decorator.

it was <mvc:resources /> that was not accepting the post requests for the decorator file as sitemesh was trying to access it using a Post request.

I changed the mapping of my decorator file to make sure it was static and responded to POST and GET requests. More details here Spring: not accept POST request under mvc:resources? how to fix that

The code I used is

<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>
Community
  • 1
  • 1
Rob
  • 703
  • 1
  • 7
  • 18
0

Well as you figured out that the problem was with sitemesh. this link is to a project integrating springMVC with sitemesh

Muhammad Bekette
  • 1,396
  • 1
  • 24
  • 60
  • Hi there, I failed to find any information from your link, would you please please paste the proper link to me again? thank you – Shore Apr 15 '13 at 13:59
  • well it is a link to a real project where it uses sitemesh and springMVC and I thought it would help to check it out in you machine you could use this link http://petclinicplus.googlecode.com/svn/ since you're not a member of this project then you will have to check it as readonly – Muhammad Bekette Apr 15 '13 at 15:00
  • yes, I reviewed the code, and I think the code using sitemesh2.3, but I'm using sitemesh3, I don't know whether 2.3 has the same problem, will do a testing – Shore Apr 15 '13 at 15:58