In springMVC, the background data interaction with the page is performed through ModelAndView. So how do you get the value bound to the ModelAndView in the page?
1. Get it through EL expressions in JSP (more commonly used)
Backstage:
ModelAndView model = new ModelAndView();model.addObject("name","Jims");JSP: Use ${name} directly to get it in JSP
Name: ${name }2. Get it through built-in JSP
Backstage:
ModelAndView model = new ModelAndView();model.addObject("name","Jims");front desk:
<% String name = request.getAttribute("name"); %>The above two methods are to get the value bound by ModelAndView in JSP. So how to get the value bound by ModelAndView in JS of the page?
1. The most troublesome one:
Backstage:
ModelAndView model = new ModelAndView();model.addObject("name","Jims");JSP:
<input type="hidden" value="${name }" id="method1">JS:
var name = $("#method1").val();2. Similar to the first type:
Backstage:
ModelAndView model = new ModelAndView();model.addObject("name","Jims");JSP:
<% String name=request.getAttribute("name"); %>JS:
var name='<%=name %>';
3. The third type is simpler and more commonly used
Backstage:
ModelAndView model = new ModelAndView();model.addObject("name","Jims");JS:
var name = '${name}';In this way, you can directly obtain the name attribute bound in ModelAndView
The above brief discussion on how to get the value of ModelAndView binding on the page is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.