檢查插入Bean類是否省略setter方法, 整型變量是在我下面的示例代碼確定:
public int getDeptId() {
return deptId;
}
public class Produce {
private String name="電吉他";
private double price=1880.5;
private int count=100;
private String factoryAdd="吉林省長春市";
public double getPrice() {
return price;
}
public String getFactoryAdd() {
return factoryAdd;
}
public String getName() {
return name;
}
public void setCount(int count) {
this.count = count;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:useBean id="produce" class="net.cs30.Produce"></jsp:useBean>
<jsp:setProperty name="produce" property="name" value="洗衣機"/>
<jsp:setProperty name="produce" property="count" value="12306"/>
<div>
<ul>
<li>商品名稱:<jsp:getProperty name="produce" property="name"></jsp:getProperty></li>
<li>廠址:<jsp:getProperty name="produce" property="count"/></li>
</ul>
</div>
</body>
</html>
這是我輸出的screenshot。
你能分享你的代碼嗎? –
請附上其他代碼片段(例如bean),真正能夠解決問題的任何東西。 –
bean擁有成員String name,String address,String gender和Integer deptId。我可以使用jsp:setProperties將值設置爲名稱,地址和性別,但它不適用於deptId – One