在jsp頁面中獲取JavaBean的屬性資訊
阿新 • • 發佈:2019-01-22
JavaBean:
package com.wgh;
public class Produce {
// 商品名稱
private String name = "程式設計詞典個人版";
// 商品價格
private double price = 298;
// 數量
private int count = 10;
// 出廠地址
private String factoryAdd = "吉林省明日科技有限公司";
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public int getCount() {
return count;
}
public String getFactoryAdd() {
return factoryAdd;
}
}
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:useBean id="produce" class="com.wgh.Produce"></jsp:useBean>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>顯示商品資訊</title>
</head>
<body>
<div>
<ul>
<li>
商品名稱:<jsp:getProperty property="name" name="produce"/>
</li>
<li>
價格:<jsp:getProperty property="price" name="produce"/>(元)
</li>
<li>
數量:<jsp:getProperty property="count" name="produce"/>
</li>
<li>
廠址:<jsp:getProperty property="factoryAdd" name="produce"/>
</li>
</ul>
</div>
</body>
</html>