el表達式無法獲取springmvc的model封裝好的數據之解決方法


近日碰到奇怪的問題,應該挺好解決的,可是就是卡住我兩天

下面我來描述一下問題

用的是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是沒法使用的。

就這么簡單的問題,竟然卡住了我兩天,可見能卡住我們的,才是經驗的積累。
如果什么都很順暢的話,錢也太好賺了不是嗎?


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM