• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem handling HTTP Request with different parameters

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am going crazy trying to handle the following situation:

In a view I have the following 3 links that all generate an HTTP Request towards the "/mapping/parameter" folder. These links differ from each other for the parameter passed, so the first one pass a parameter named foo, the second one pass a parameter named foo2 and the last one pass no parameter.



Now, in my controller class, I would handle this situation using 3 different methods, so I added the following methods to my controller:



The problem is that in this way is handled only the !foo, !foo2 case and if I click on the first link (the one with the parameter naming foo) I obtain the following error in the stack trace:

nov 24, 2012 9:10:29 PM org.apache.catalina.core.StandardWrapperValve invoke
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.byParameter(), 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.byParameter(), 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)

And if I click on the second link (the one with the parameter naming foo) I obtain the following error in the stack trace:

nov 24, 2012 9:11:27 PM org.apache.catalina.core.StandardWrapperValve invoke
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)

Why? How can I resolve?

Thanks
Andrea









 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't put two params like that in params=""

But you could do it in code. Pass in the HttpServletRequest and look yourself.

Or have the first two methods, then the third not have params in it. It might be that the first two are checked first then the third. And in the third pass HttpServletRequest and make sure they aren't in there.

Mark
 
Andrea Nobili
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:You can't put two params like that in params=""

But you could do it in code. Pass in the HttpServletRequest and look yourself.

Or have the first two methods, then the third not have params in it. It might be that the first two are checked first then the third. And in the third pass HttpServletRequest and make sure they aren't in there.

Mark



mmm, ok...so I have undestrand that I can not have something like params="!foo, !foo2".

But I have not understand how can I solve this situation, can you help me? :-(

Thanks
Andrea
 
Andrea Nobili
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,
doing so seem to work well:



So I have a method that handle only the http request towards "mapping/parameter" and two other method for the same folder with one parameter: foo and foo2

I have an other theorical doubt probably most related about Java rather than about Spring framework

You have give me this link: http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameter%28java.lang.String%29
This link is the Java Docs and there is nothig about Spring framework docs.

Now I have study the getParameter method documentation and I have see that this method belongs to java.lang.String that is one of the standard Java library...

So it means that when in my code I use the annotation: @RequestParam("foo2") String foo2 the Spring framework call for me the getParameter method from the java.lang.String class and put this value inside a new String variable? I have well understand?

In practice when I call a Spring annotation, Spring framework call form me some his method that do something? (in this case: call the java.lang.String.getParameter() method and put the returned value inside a String variabile whose name is declared by the developer in the annotation body)

Thank you very much for your help
Andrea

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't give you any link. In my post, I entered in nothing of a link. But it looks like the browser or something else, which happens a lot places on the internet, did a search or created a popup with a link. I did not put that there.

getParameter is not on the String class, it returns a String, but is in the HttpServletRequest class.

And @RequestParam means Spring will go into the HttpServletRequest and call getParameter on that class for you. It will also convert the String that returns to the type of the parameter in your Controller method.

Mark
 
Andrea Nobili
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I didn't give you any link. In my post, I entered in nothing of a link. But it looks like the browser or something else, which happens a lot places on the internet, did a search or created a popup with a link. I did not put that there.

getParameter is not on the String class, it returns a String, but is in the HttpServletRequest class.

And @RequestParam means Spring will go into the HttpServletRequest and call getParameter on that class for you. It will also convert the String that returns to the type of the parameter in your Controller method.

Mark



Ok,
now it is very clear :-)

Tnx
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic