Reputation: 3067
I am new with Spring mvc. I need to pass an javascript variable to controller. How to achieve this??
Form tag solution is not appropriate in case of my application.
I need to pass this start variable of JS to my controller.In some cases this variable can be null or not available as per requirements.
Please suggest asap!!!
My JS code is:
function clickPaginate(start){
var X = '<%=url%>';
window.location.href=X+'/library/${publisher}';
}
and controller is:
@RequestMapping(value = "/library/{publisher}", method = RequestMethod.GET)
public String getPublisherDetails(@PathVariable("publisher") String publisher, ModelMap model) throws FeedsException {
}
Upvotes: 0
Views: 4040
Reputation: 769
There is an annotation @RequestParam
that you'll have to use in the method. In your case
window.location.href=X+'/library/${publisher}?foo=bar';
foo
is the request parameter with value bar
that you are passing to your method.
Your method should be like
public String getPublisherDetails(@RequestParam("foo") String foo, @PathVariable("publisher") String publisher, ModelMap model)
Check out this mvc doc
Upvotes: 1