近日碰到奇怪的问题,应该挺好解决的,可是就是卡住我两天
下面我来描述一下问题
用的是springmvc,自然需要controller,假设我现在所有的配置都是对的。
controller代码
@RequestMapping(method = RequestMethod.GET)
public String update(Model model) {
System.out.println("service update");
model.addAttribute("greetings", "I came from Model not ModelAttribute");
System.out.println(model.toString());
return "success";
}
成功后的html画面
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<h2>Add Book</h2>
bookname:<input type="text" name="name" id="name" value="${book.name}">
author:<input type="text" name="author" id="author" value="${book.author}">
<p><c:out value="${greetings}" /> </p>
<p>${greetings}</p>
</body>
</html>
最后页面上始终是${greetings}
奇怪就奇怪在这里,图上也可以看到了,我用c:out也试过了,就是失败。
解决方法:
这个解决方法绝对够简单,但是就是想不到 原来是<%@ page isELIgnored="false" %>没有加 如果一定要追查为什么,只能说,默认EL的忽略是true的,所以EL是没法使用的。
就这么简单的问题,竟然卡住了我两天,可见能卡住我们的,才是经验的积累。 如果什么都很顺畅的话,钱也太好赚了不是吗? |