0

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 {

}

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.