我正在尝试使用JSTL在动态生成的表的每一行上获取一个删除按钮。 使用forEach方法生成表时,所有数据库字段都没有问题。当我尝试对ID(整数和表主键)执行相同操作时,它会给出错误 "财产' cars_id'在logon.Car"类型上找不到。可以使用resultList.get(1).getID()从结果列表中提取它们,并且它在屏幕上打印到jsp页面没问题。
这里有什么我想念的吗?任何IDeas?
我的JSP:
<%
List<Car> resultList = new ArrayList<Car>();
resultList=(List<Car>)request.getAttribute("ResultList");
%>
<table border="1">
<thead title="Current Cars"/>
<tr><th>Make:</th><th>Model:</th><th>Year:</th><th>Colour:</th><th>Information:</th></tr>
<tbody>
<c:forEach items="${ResultList}" var="car">
<tr>
<td>${car.carMake}</td>
<td>${car.model}</td>
<td>${car.carYear}</td>
<td>${car.carColour}</td>
<td>${car.information}</td>
<td>
<form action="CarServlet" method="get">
<input type="hidden" name="carId" value="${car.cars_id}" />
<input type="submit" value="Remove" name="remove">
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
我的Car.java
@Entity
@Table(name = "cars")
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int cars_id;
@Column(name = "cars_make")
private String carMake;
@Column(name = "year")
private String carYear;
@Column(name = "colour")
private String carColour;
@Column(name="information")
private String information;
@Column(name="model")
private String carModel;
//NOTE:"user_id" below in (@JoinColumn(name="user_id"))...is the name
//of the field in my sql that corresponds to id from User table
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({ @JoinColumn(name = "user_id", referencedColumnName="id") })
private User user;
public User getUser() {
if (user == null) {
user = new User();
}
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getCar_id() {
return cars_id;
}
public void setCar_id(int cars_id) {
this.cars_id = cars_id;
}
public String getCarMake() {
return carMake;
}
public void setCarMake(String carMake) {
this.carMake = carMake;
}
public String getModel() {
return carModel;
}
public void setModel(String carModel) {
this.carModel = carModel;
}
public String getCarYear() {
return carYear;
}
public void setCarYear(String carYear) {
this.carYear = carYear;
}
public String getCarColour() {
return carColour;
}
public void setCarColour(String carColour) {
this.carColour = carColour;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
}
答案 0 :(得分:2)
${car.cars_id}
应为${car.car_id}
EL
字段名称应与bean方法名称匹配,而不是类字段本身。