我有 Spring Controller ,我将一些属性映射到模型,然后通过 jsp 页面显示模型信息...问题是所有属性(即 ${attributeName}
- 这就是我得到的渲染的页面)按定义显示,没有值。到目前为止,这一切都运行良好。我怀疑其中一个库丢失了,但不知道是哪一个......
提前致谢。
Controller 示例
@RequestMapping(value="/entity", method=RequestMethod.GET)
public String getEntity(@RequestParam (value="q", required=true) String q, Model model){
model.addAttribute("q", q);
return "viewName"; //this is jsp file name
}
viewName.jsp
${q}
当我调用 localhost:8080/controller/entity?q=string 时,输出应该是“string”,但输出是 ${q}
最佳答案
使用 ModelMap 映射
代替 Controller 函数中的 Model 模型,然后在该映射中添加您的属性。
还要检查您的jsp 顶部的页面目录。该标记中是否有任何属性,如 isELIgnored='true'
,然后将其删除,然后尝试使用它。
我认为它应该可以解决您的问题。
干杯。
关于java - JSP获取属性定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10813705/