title: Taking an HTTP Request parameter in Spring MVC
body: <p>
  I have a problem taking a parameter of an HTTP request in Spring MVC.</p>
  
  <p>In my view I have the following link:</p>
  
  <pre class="lang-java prettyprint-override"><code>&lt;li&gt;
    &lt;a id="byParameter2" class="textLink" 
     href="&lt;c:url value="/mapping/parameter?myparam=blabla" /&gt;"&gt;(PERSONALE) By path, method, and presence of parameter with value="blabla"&lt;/a&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>And this is my controller class code:</p>
  
  <pre class="lang-java prettyprint-override"><code>package org.springframework.samples.mvc.mapping;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.springframework.http.MediaType;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  @Controller
  
  public class MappingController {
  
  /* Gestisce HTTP Request di tipo GET che contengono un parametro di nome "foo" verso il percorso "/mapping/parameter"
   * Restituisce una stringa nel campo body della HTTP Response
   */
  @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo")
  public @ResponseBody String byParameter() {
      return "Mapped by path + method + presence of query parameter!";
  }
  
  /* (PERSONALE) Gestisce richieste HTTP di tipo GET verso il path "/mapping/parameter" solo se NON contengono un parametro di input di nome "myparam"
   * e ne estrae il valore */
  @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="myparam")
  public @ResponseBody String byParameter(@RequestParam("myparam") String myparam) {
      return "Mapped by path + method + presence of query parameter! (MappingController). Parameter value = " + myparam;
      }
  
  
  /* Gestisce HTTP Request di tipo GET che NON contengono un parametro di nome "foo" verso il percorso "/mapping/parameter"
   * Restituisce una stringa nel campo body della HTTP Response 
  */
  @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="!foo")
  public @ResponseBody String byParameterNegation() {
      return "Mapped by path + method + not presence of query parameter!";
  }
  
  
  }
  </code></pre>
  
  <p>The problem is that when I run my application if I click on the link that generates the HTTP Request towards <code>"/mapping/parameter?myparam=blabla"</code> this request is not handled by my <code>public @ResponseBody String byParameter(@RequestParam("myparam") String myparam)</code> method and I have the following error message in the browser:</p>
  
  <pre class="lang-java prettyprint-override"><code>**HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/spring-mvc-showcase/mapping/parameter': {public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameter2(java.lang.String), public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameterNegation()}**
  
  And the following error in the stack trace:
  
  **SEVERE: Servlet.service() for servlet [appServlet] in context with path [/spring-mvc-showcase] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/spring-mvc-showcase/mapping/parameter': {public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameter2(java.lang.String), public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameterNegation()}] with root cause
  java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/spring-mvc-showcase/mapping/parameter': {public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameter2(java.lang.String), public java.lang.String org.springframework.samples.mvc.mapping.MappingController.byParameterNegation()}
      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:262)
      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:212)
      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:55)
      at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:297)
      at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091)
      at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:917)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:813)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:798)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)**
  </code></pre>
  
  <p>Why? Where is the problem? How can I solve it?</p>