Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your mappings are not completely correct @TMan:</p> <ol> <li><p>The mappings in web.xml are to get Spring Dispatcher servlet to handle your request - eg. like in your case:</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:/META-INF/appServlet/servlet-context.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; </code></pre> <p></p> <p> appServlet *.do So now any request to URI's ending with .do will be handled by Spring's DispatcherServlet</p></li> <li><p>The controller can have a mapping, like in your case:</p> <p>@Controller @RequestMapping(value="/search.do")</p></li> </ol> <p>But where you have gone wrong is in the RequestMapping for the controller :</p> <pre><code>@Controller @RequestMapping(value="/search") </code></pre> <p>The .do at the end of RequestMapping should not be there, as it is purely for the Dispatcher servlet to be invoked, once that is invoked it will handle dispatching to the correct Controller method, so your call to /search.do will end up with the controller.</p> <ol start="3"> <li><p>Now, each method can be annotated with RequestMapping like in your case, with a RequestMethod atribute of RequestMapping, specifying whether to dispatch to the method in case of POST or GET:</p> <pre><code>@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.POST) </code></pre></li> </ol> <p>So when there is a POST to the /search.do URI the appropriate method will be called.</p> <p>In your case, there are multiple methods annotated with the RequestMethod.POST attribute, so the <code>AnnotationMethodHandlerAdapter</code> component of Spring simply doesn't know which method to dispatch to.</p> <p>There are a couple of things that you can do:</p> <ol> <li><p>put a request mapping for each method, the way suggested by @Bozho: @RequestMapping(value="/customers" method=Request.POST) @RequestMapping(value="/products" method=Request.POST) so now your request URI's would be</p> <p>/search/customers.do /search/products.do and you should be doing POST to get the correct dispatch method.</p></li> <li><p>Get rid of method=Request.POST all together and depend on the @RequestMapping like above to find the correct method.</p></li> <li><p>You can pass an optional params attribute to RequestMapping, which again is a way to help Spring find your correct method to dispatch to:</p> <p>@RequestMapping(method=Request.POST, params="customers")</p></li> </ol> <p>with customers parameters in the request or say products parameters in the request.</p> <p>The simplest will be option 1 though.</p> <p>EDIT 1: Adding a reference to a good Spring document - <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html" rel="noreferrer">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload