servlet和jsp學習指南(五)EL運算式

來源:互聯網
上載者:User

標籤:import   and   html   htm   throw   att   image   protected   tutorial   

EL運算式的具體用法我暫時先不說了

這裡就簡單說說注意點

package test.com.servlet.jstl;public class Book {    private String isbn;    private String title;    private Double price;        public Book(String isbn,String title,double price) {        this.isbn = isbn;        this.title = title;        this.price = price;    }    public String getIsbn() {        return isbn;    }    public void setIsbn(String isbn) {        this.isbn = isbn;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }    public Double getPrice() {        return price;    }    public void setPrice(Double price) {        this.price = price;    }    }

 

package test.com.servlet.jstl;import java.io.IOException;import java.util.ArrayList;import java.util.List;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet(urlPatterns = {"/books"})public class BooksServlet extends HttpServlet{    /**     *      */    private static final long serialVersionUID = -8775932947610791148L;    @Override    protected void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        List<Book> books = new ArrayList<Book>();        Book book1 = new Book("978-213213213", "Java 7:A Beginner‘s Tutorial", 45.00);        Book book2 = new Book("978-446767456", "Struts 2 Design and Programming: A Tutorial", 49.95);        Book book3 = new Book("978-545644452", "Dimensional Data Warehousing with MySQL: A Tutorial", 39.95);        books.add(book1);        books.add(book2);        books.add(book3);        request.setAttribute("books", books);        RequestDispatcher rd = request.getRequestDispatcher("/books.jsp");        rd.forward(request, response);    }    }
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Book List</title></head><body>Books in Simple Table<table>    <tr>        <td>ISBN</td>        <td>Title</td>    </tr>    <c:forEach var = "book" items="${books }">        <tr>            <td>${book.isbn }</td>            <td>${book.title }</td>        </tr>    </c:forEach></table></body></html>

訪問後頁面如下

${book.isbn }這個怎麼取值的?

其實是通過Book的getIsbn()

不信咱們把getTitle()方法注釋起來再訪問下試試

結果就成這樣了

javax.el.PropertyNotFoundException: Property ‘title‘ not readable on type test.com.servlet.jstl.Book    at javax.el.BeanELResolver$BeanProperty.read(BeanELResolver.java:357)    at javax.el.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:305)    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)......

所以簡單理解,他是通過實體屬性的get方法獲得的

 

servlet和jsp學習指南(五)EL運算式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.