So, say I have an existing, working page Display Cashier
, which displays information about a cashier in a shop. Now, I add a button to this page that looks like:
<a href="handleGetManager.ctl?cashierId=${id}" class="btn btn-mini">Manager</a>
The request-mapping for this URL maps it (successfully) to a controller: HandleGetManager
the HandleGetManager
controller looks like this:
@Controller
public class HandleGetManager{
private employeeBO employeeBO; //BO handles all business logic
//spring hooks
public HandleGetManager(){}
public void setemployeeBo(employeeBO employeeBO){
this.employeeBO = employeeBO;
}
//get controller
@RequestMapping(method=RequestMethod.GET)
public String getManager(@RequestParam String cashierId){
Long managerId = employeeBO.getManagerByCashierId(cashierId);
String redirectUrl = "/displayManager.ctl?managerId=" + managerId.toString();
return redirectUrl;
}
}
Here's what happens when I try it:
I hit the new button on the Display Cashier
page, I expect the following to happen:
The browser sends a get request to the indicated URL
The spring request-mapping ensures that the flow of control is passed to this class.
the
@RequestMapping(method=RequestMethod.GET)
piece ensures that this method is evokedThe
@RequestParam String cashierId
instructs Spring to parse the URL and pass the cashierId value into this method as a parameter.The EmployeeBo has been injected into the controller via spring.
The Business logic takes place, envoking the BO and the
managerId
var is populated with the correct value.The method returns the name of a different view, with a new managerId URL arg appended
Now, up until this point, everything goes to plan. What I expect to happen next is:
the browsers is directed to that URL
whereupon it will send a get request to that url,
the whole process will start again in another controller, with a different URL and a different URL arg.
instead what happens is:
this controller returns the name of a different view
The browser is redirected to a half-right, half wrong URL:
handleGetManager.ctl?managerId=12345
The URL argument changes, but the name of the controller does not, despite my explicitly returning it
I get an error
What am I doing wrong? Have I missed something?