Matching URL pattern with @RequestMapping
jsp, spring, spring-mvc, url
Solution
You need to put slash on `@RequestMapping`, like:
@RequestMapping(value = {"/activate/{key}"}, method = RequestMethod.GET)
public ModelAndView activate(@PathVariable(value = "key") String key) {
...
}
Anyway, if you wat to get access to following context:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/activate/</url-pattern>
</servlet-mapping>
You cant try this:
@RequestMapping(value = {"/{key}"}, method = RequestMethod.GET)
public ModelAndView activate(@PathVariable(value = "key") String key) {
...
}
[Edited]
Like Leonel said, you should have this configuration to use with full URL (`@RequestMapping(value = {"/activate/{key}"}`):
<url-pattern>/</url-pattern>
Problem
It's quite similar to this question, but I just couldn't figure out how to match the url pattern. web.xml: ``` <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/activate/*</url-pattern> </servlet-mapping> ``` My controller: ``` @RequestMapping(value = {"activate/{key}"}, method = RequestMethod.GET) public ModelAndView activate(@PathVariable(value = "key") String key) { ... } ``` When I try to access `localhost:9999/myApp/activate/123456789`, I get the following error: ``` No mapping found for HTTP request with URI [/myApp/activate/123456789] in DispatcherServlet with name 'dispatcher' ``` I also tried `<url-pattern>/*</url-pattern>`, same thing happens. However, by changing `<url-pattern>/activate/*</url-pattern>` to `<url-pattern>/**</url-pattern>` no error appears, but i still get 404. So, how do I map this url pattern?