简体   繁体   中英

Retrieve ModelMap value from Spring MVC controller to jquery in html

I am doing project in Spring 4.0.2. In Spring MVC controller I have used ModelMap attributes and I want to retrieve the same in jquery in html file.

My Servlet code

@RequestMapping(value = "/search", method = RequestMethod.GET)
public String search(ModelMap model,@ModelAttribute TravelSearchDTO travelSearchForm, HttpServletRequest request) {
    Integer maxSeatSelection = dto.getMaxSeats();
    model.addAttribute("maxSeatNo",maxSeatSelection);       
    String returnText = "static/html/search";
    return returnText;
}

My jquery code in search.html

<script type="text/javascript">
var ss = '${maxSeatNo}'; 
alert(ss);
</script>

No alert for ss value appeared. Also I am in great doubt that whether I need to use the variable in script declaration or in document.ready function. Please clarify above doubts to access the Modelmap value in html.

Try using var ss = "${maxSeatNo}"; This should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM