How can I create a URL based on controller and action method in Spring MVC?

后端 未结 4 1528
情歌与酒
情歌与酒 2020-12-17 17:38

I am using Spring MVC 3.0

I have a guestbook.jsp page where I want to create a link that points to GuestBookController\'s login method.

This is a simple task

4条回答
  •  甜味超标
    2020-12-17 17:53

    Annotate your login method with @RequestMapping, like so:

    @Controller
    public class GuestBookController {
      ...
      @RequestMapping(value="/mycontextroot/login", method = RequestMethod.GET)
      public String login() {
        ...
      }
      ...
    }
    

    Then, in your JSP, create a link something like this:

    
    
    Login
    

    This assumes that your dispatcher servlet is looking for *.html URLs.

提交回复
热议问题