2
我有一个Spring MVC Web应用程序,它使用View技术的JSP。在控制器中,我将值注入到ModelAndView
对象中,然后使用它(用各自的JSP)来帮助构建最终的HTML以返回到客户端。从Spring MVC控制器注入JSP
控制器:
@RequestMapping(value = "/widgets.html", method = RequestMethod.POST)
public ModelAndView widgets(@Model Fruit fruit, @RequestParam("texture") String texture) {
ModelAndView mav = new ModelAndView();
// The name of the JSP to inject and return.
max.setViewName("widgets/AllWidgets");
int buzz = calculateBuzzByTexture(texture);
mav.addObject("fruitType", fruit.getType());
mav.addObject("buzz", buzz);
return mav;
}
该控制器(用来处理/widgets.html
请求)做一些查询和返回注入AllWidgets.jsp
页面。在那个JSP页面中,我需要访问fruitType
和buzz
变量(在HTML和JS中),但不知道如何做到这一点。举例来说,假设fruitType
是一个String(和buzz
是int
),我怎么会打印出来HTML和JS:提前
<script type="text/javascript>
alert("Buzz is " + buzz);
</script>
<div>
<h2>The type of fruit is ??? fruitType ???</h2>
</div>
感谢。
谢谢@parsifal(+1) - 我*假设*在JavaScript内部也一样吗?再次感谢! – IAmYourFaja