RequestMapping « MVC « Spring Q&A

1. Spring 3 MVC Nesting RequestMapping

From Spring Official Document, Spring 3 MVC look to be support nesting Request Mapping. In page 448, they mentioned:

public class AppointmentsController {
    @RequestMapping(value="/new", method = RequestMethod.GET)

2. How to match a Spring @RequestMapping having a @pathVariable containing "/"?

I am doing the following request from the client: /search/hello%2Fthere/ where the search term "hello/there" has been URLencoded. On the server I am trying to match this URL using the following request mapping:

public ...

3. Multiple Spring @RequestMapping annotations

Is it possible to use multiple @RequestMapping spring annotations in a method? Like:

public String welcomeHandler(){

4. Spring @RequestMapping and trailing slash problem

I am trying to map a method in a Controller using the annotation with URI template:

@RequestMapping(value="/select/{customerNumber}/{resource}", method=RequestMethod.GET)
It appears that this does not get mapped if there is a trailing slash at ...

5. Can i use Spring's @RequestMapping and BeanNameUrlHandlerMapping in conjuntion with each other to map a URL to method?

What I would like to do is have a common Service class which has various methods such as "search" "retriveByID" etc. Ideally this class would consume the service parameters and populate ...

6. spring 3 RequestMapping get path value

Is there a way to get the complete path value after the requestMapping pathvariable values has been parsed. That is: /{id}/{restOfTheUrl} should be able to parse /1/dir1/dir2/file.html id=1 and restOfTheUrl=/dir1/dir2/file.html Any ideas would be ...

7. spring mvc @requestmapping best practice

Checked the official ref, found a million ways to do things.
I guess I have 2 set of use cases. 1. return customized http response, basically I am responsible for filling in ...

8. RequestMapping with Spring Portlet MVC 3

I have a portal page that has two windows on it. Each window represents an instance of an annotated Spring Portlet MVC portlet. In both portlets (Controllers) I have a "default" ...

9. RequestMapping in xml

I am new to Spring MVC 3.0, I have a background of struts 2.0. I am comfortable with configuration in xml. So, I am looking for a way to represent to @RequestMapping in ...

10. Spring MVC - Basic RequestMapping question

I'm new to Spring MVC. I'm getting errors on the following (not sure yet what;s the full scope of info requierd to assist me): Working fine:

 @RequestMapping(value = "")
 public ModelAndView startpage(HttpServletRequest ...

11. How to do annotation based RequestMapping

I am calling spring controller from ajax like /test/new.ui. How to do RequestMapping in controller method. Thanks in Advance. Regards, Raju

12. Documenting Spring @RequestMapping annotations into one location automatically?

Javadoc is great for scanning all of source files and creating HTML pages to view it. I was wondering if there is a similar tool that would go through all of ...

13. How do I map different values for a parameter in the same @RequestMapping in Spring MVC?

Suppose I have:

@RequestMapping(params = "action=nuovoprodotto")    
    public ModelAndView nuovoProdotto(
            @RequestParam(value = "page", required = ...

14. How to achieve a certain url format using @RequestMapping in SpringMVC

I am trying to create a simple application using SpringMVC for learning purpose. I want to have the urls for various actions in this format

The url-pattern specified inside the servlet-mapping for ...

15. Spring MVC referencing params variable from RequestMapping

I have the method below:

@RequestMapping(value = "/path/to/{iconId}", params="size={iconSize}", method = RequestMethod.GET)
public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws IOException {
    // Implementation here
I know how ...

16. Spring MVC 3 RequestMapping with regular expresssion quantifiers

The method below fails with "PatternSyntaxException: Unclosed counted closure near index ... "

@RequestMapping(value ="/{id:[0-9|a-z]{15}}")
public View view(@PathVariable final String id) {
Looks like the pattern matcher is trimming too much off ...

17. Spring MVC @RequestMapping Inheritance

Coming from Struts2 I'm used to declaring @Namespace annotation on super classes (or and inheriting classes would subsequently pick up on the value in the @Namespace annotation of its ancestors ...

18. @RequestMapping controlers and dynamic URLs

I would like to use Spring MVC @RequestMapping annotation to attach my controller to requests in such way:

@RequestMapping(method = RequestMethod.GET, value="/prod/{value:.+}/show")
 public String getProduct(

19. Spring MVC RequestMapping matches wrong URL

I'm building a rest api for one webapp and have encountered a problem with RequestMapping. Basicaly there are users, which are grouped together into various domains. When they work with the system ...

20. How to know the moment when @RequestMapping fires?

I have a Spring MVC Controller class (bean):

public class EjbCaller {

    private InfoBean infoBean;

    public EjbCaller() {

21. @RequestMapping matching url with "." and '"x"

This is how the url matcher looks like:


@PathVariable int applicationId,
@PathVariable int groupId,
@PathVariable String pathYear,
@PathVariable String pathMonth,
@PathVariable String pathDay,
@PathVariable long imageId,
@PathVariable int width,
@PathVariable int height,
@PathVariable int version,
@PathVariable String fileExtension
A typical call would ...

22. In Spring MVC, how can I get @RequestMapping to work?

In Spring 3 MVC, I have a controller that I call RolesController, and it has methods such as displayRoles() for displaying a list of roles, saveRole(), and deleteRole(). Currently, I'm ...

23. Handling of pre-slash in @RequestMapping

Imagine that I have a Spring MVC controller something like this:

public class MyController{

    @RequestMapping(method=RequestMethod.GET, value="/edit/{id}")
    public String edit(Model model, HttpServletRequest request, ...

24. @PathVariable and @RequestMapping issues

I would like to send only the requests ending in .html through dispatcher-servlet and all other requests handled directly, so I have mapped that in web.xml..


25. RequestMapping not working with multi-level URLs

I have a scenario where I'm making a simple get request through a link and my @RequestMapping configuration is not behaving as I'd expect. Within an anchor tag I reference a url ...

26. Get requested value(URL) when using @RequestMapping annotations

When I map multiple values to @RequestMapping(like Multiple Spring @RequestMapping annotations), can I get the requested value(URL)? Like this:

@RequestMapping(value={"/center", "/left"}, method=RequestMethod.GET)
public String getCenter(Model model) throws Exception {     ...

27. Optional path variables in Spring-MVC RequestMapping URITemplate

I have the following mapping:

@RequestMapping(value = "/{first}/**/{last}", method = RequestMethod.GET)
public String test(@PathVariable("first") String first,  @PathVariable("last")  
  String last) {}
Which for the following URIs:
maps foo to first and bar ...

28. @RequestMapping not working?

I have the following annotation:

@RequestMapping(value = "/login", method = { RequestMethod.GET, RequestMethod.POST })
However can't seem to load the page. The odd thing is I have other annotations I can make ...

29. Spring Mvc @RequestMapping

Can anyone explain what is the difference between 1. @RequestMapping("/") 2. @RequestMapping("/*") 3. @RequestMapping("/**") Thanks in advance

30. How to configure mapping to take precedence over @RequestMapping

@Controller public class ProxyController { @RequestMapping(value = "/?*/**", method = RequestMethod.GET ) public void forwardGet(HttpServletRequest request, HttpServletResponse response) { ..... handle unmapped GETs } }

31. Diff in Spring MVC 3.0 & 2.5 @RequestMapping behavior

Diff in Spring MVC 3.0 & 2.5 @RequestMapping behavior I've found a difference in the behavior of Spring MVC with respect to @RequestMapping annotations -- in Spring 3.0.2.RELEASE, the following example ...

32. MVC requestmapping method automatically submitted

MVC requestmapping method automatically submitted Hi all, I have a controller which changes a simple form. You must logged in to see the form. I opened the form in two browser ...