How to redirect to a jsp from another controller in java?

0

I have the following method in my controller, which sends me to the login page

@RequestMapping(value= "/login", method= RequestMethod.GET)
public String irPaginaLogin(){
  return "/login";
}

and it contains the following fields:

<input type="text" class="form-control text-lowercase" id="username" name="username"/>


<input type="text" class="form-control text-lowercase" id="password" name="password"/>

<input type="submit" class="btn btn-block btn-primary" value="Entrar" onclick=""/>

Now what I want to do is that when I click on the Enter button I redirect to another "menu" page, that "menu" page I have declared in another controller, in the following method:

@RequestMapping(value= "/menu", method= RequestMethod.GET)
public String mostrarMenu(){
  return "/menu";
}

How can I redirect to that method that shows the menu ?? or how can I add a small validation to put a username and password and with that logearme?

    
asked by Root93 22.08.2018 в 06:24
source

1 answer

1

First, it looks like you are in a form, so I guess you should send the request with POST instead of with GET. I'm telling you because I see that your showMenu function uses GET. If what you want is to send the values of the form, that is, the user and password, the easiest thing is that in the definition of your form, put something like this:

form action="/menu"

And change in your function to collect the values of your form (that for something you will have them). Something like this:

@RequestMapping(value= "/menu", method= RequestMethod.GET)
public String mostrarMenu(@PathVariable("username") String username,@PathVariable("password") String password)
{
....
}
    
answered by 22.08.2018 в 08:08