Spring mvc Spring MVC中控制器中的RequestMapping有时会发生变化

Spring mvc Spring MVC中控制器中的RequestMapping有时会发生变化,spring-mvc,Spring Mvc,我试图在我的web应用程序中实现SpringMVC,我有一个控制器类 @Controller<br> public class ContactController { @Autowired<br> private ContactService contactService; @RequestMapping("/login") public String displayLoginPage(HttpServletRequest httpReq, @ModelAttribu

我试图在我的web应用程序中实现SpringMVC,我有一个控制器类

@Controller<br>
public class ContactController {
@Autowired<br>
private ContactService contactService; 

@RequestMapping("/login")
public String displayLoginPage(HttpServletRequest httpReq, @ModelAttribute("login") Login login, BindingResult result){
    return "login";
}

/*Spring will automatically calls this method whenever it encounters "/home" url in request.*/
@RequestMapping("/login/home")
public String displayHomePage(HttpServletRequest httpReq, Map<String, Object> map){
    map.put("contact", new Contact());
    map.put("contactList", contactService.listContact());
    return "contact";
}}
@Controller
公共类联系人控制器{ @自动连线
私人联络服务; @请求映射(“/login”) 公共字符串displayLoginPage(HttpServletRequest httpReq、@ModelAttribute(“登录”)登录登录、BindingResult){ 返回“登录”; } /*Spring将在请求中遇到“/home”url时自动调用此方法*/ @请求映射(“/login/home”) 公共字符串显示主页(HttpServletRequest HttpRequest,映射){ map.put(“contact”,newcontact()); map.put(“contactList”,contactService.listContact()); 返回“联系人”; }}
启动应用程序后,会出现登录屏幕,然后单击按钮,我发现RequestMapping的值有时会发生变化。有时是“/登录/主页”,有时是“/主页”。为什么这不是常数?有没有办法让我知道什么是requestMapping,这样我就可以将它转发到控制器中的相应方法

PS:在login.jsp中,我有如下代码:

form action=“home”commandName=“login”


如果form
action
不是以斜杠(
/
)开头,则表单将提交到相对于当前地址的地址


如果您已经在
登录
页面上(即您的当前地址已经以
/login
结尾),并且您已经指定了
表单action=“home”
,表单将提交到当前地址,并在末尾附加
home
,因此结果是
/login/home
,映射到控制器方法之一。

您的
操作
相对指向
主页
。因此,如果表单所在的页面位于
/login/
下,则
主页将是
/login/home
。如果页面位于
/whater/
下,则
主页将是
/whater/home