1

Within the @Controller of a search engine:

@RequestMapping(value = "/search/{query}", method = RequestMethod.GET)
public String search(@PathVariable String query) {}

If a user wants to search /search/w?rld (which should match world, warld, whrld, etc.), the variable query equals w, because of the question mark which indicated a GET var.

I tried "/search/{query:.+}", but still doesn't work.

Any idea how to solve that problem?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
sp00m
  • 47,968
  • 31
  • 142
  • 252

2 Answers2

5

The problem is not in the Spring configuration. It's in the URL. The question mark is the symbol indicating the start of the query String. If it's part of the URL, it must be encoded:

/search/w%3Frld
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks, but I want a user to be able to write his query directly within an URL in his browser, without that he has to manually escape the question marks himself. – sp00m Jun 04 '12 at 11:58
  • Then learn him to escape the question mark, because there's no way around it. – JB Nizet Jun 04 '12 at 12:01
0

if it is just for one method :

Spring MVC - How to get all request params in a map in Spring controller?

add WebRequest req to your signature method then Map parameters = req.getParameterMap();

Community
  • 1
  • 1
romu31
  • 821
  • 9
  • 17