javax.servlet.jsp.JspTagException:不知道如何遍历提供的"items" <forEach>



我确实试图遵循这篇文章中类似问题的解决方案,但不知何故,我仍然得到了错误:

javax.servlet.jsp.JspTagException:不知道如何迭代<对于每个>

我在物体中有物体。作为一个新手,我不知道如何打印。

@Component
@Entity
@Table(name = "CUSTOMER")
public class CustomerVO {
@Id
@SequenceGenerator(name = "customer_seq", sequenceName = "CUSTOMER_SEQ", 
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "customer_seq")
@Column(name = "ID")
private int id;
@Column(name = "CUSTOMERID")
private long customerId;
@Column(name = "LOGINID")
private String loginId;
@Column(name = "PASSWORD")
private String password;
@UpdateTimestamp
@Column(name = "MODIFIED_TIMESTAMP")
private Timestamp modTimestamp;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "CUST_PROFILE_ID")
private CustomerProfileVO customerProfileVO = new CustomerProfileVO();
public CustomerVO() {
}
public CustomerVO(int id, long customerId, String loginId, String password, 
Timestamp modTimestamp,
CustomerProfileVO customerProfileVO) {
this.id = id;
this.customerId = customerId;
this.loginId = loginId;
this.password = password;
this.modTimestamp = modTimestamp;
this.customerProfileVO = customerProfileVO;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public String getLoginId() {
return loginId;
}
public void setLoginId(String loginId) {
this.loginId = loginId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Timestamp getModTimestamp() {
return modTimestamp;
}
public void setModTimestamp(Timestamp modTimestamp) {
this.modTimestamp = modTimestamp;
}
public CustomerProfileVO getCustomerProfileVO() {
return customerProfileVO;
}
public void setCustomerProfileVO(CustomerProfileVO customerProfileVO) {
this.customerProfileVO = customerProfileVO;
}
@Override
public String toString() {
return "CustomerVO [id=" + id + ", customerId=" + customerId + ", 
loginId=" + loginId + ", password=" + password
+ ", modTimestamp=" + modTimestamp + ", customerProfileVO=" + 
customerProfileVO + "]";
}
}

客户档案O.java

@Component
@Entity
@Table(name = "CUSTOMER_PROFILE")
public class CustomerProfileVO {
@Id
@SequenceGenerator(name = "customer_profile_seq", sequenceName = 
"CUSTOMER_PROFILE_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = 
"customer_profile_seq")
@Column(name = "ID")
private int id;
@Column(name = "FIRSTNAME")
private String firstName;
@Column(name = "LASTNAME")
private String lastName;
@Column(name = "AGE")
private int age;
@Column(name = "GENDER")
private char gender;
@Column(name = "DOB")
private Date dob;
@Column(name = "DOORNO")
private int doorNo;
@Column(name = "STREETNAME")
private String streetName;
@Column(name = "CITY")
private String city;
@Column(name = "STATE")
private String state;
@Column(name = "ZIPCODE")
private String zipcode;
@Column(name = "PROFILESTATUSCODE")
private String profileStatus;
public CustomerProfileVO() {
}
public CustomerProfileVO(int id, String firstName, String lastName, int age, char gender, Date dob, int doorNo,
String streetName, String city, String state, String zipcode, String profileStatus) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.gender = gender;
this.dob = dob;
this.doorNo = doorNo;
this.streetName = streetName;
this.city = city;
this.state = state;
this.zipcode = zipcode;
this.profileStatus = profileStatus;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public int getDoorNo() {
return doorNo;
}
public void setDoorNo(int doorNo) {
this.doorNo = doorNo;
}
public String getStreetName() {
return streetName;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public String getProfileStatus() {
return profileStatus;
}
public void setProfileStatus(String profileStatus) {
this.profileStatus = profileStatus;
}
@Override
public String toString() {
return "CustomerProfileVO [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", age=" + age
+ ", gender=" + gender + ", dob=" + dob + ", doorNo=" + doorNo + ", streetName=" + streetName
+ ", city=" + city + ", state=" + state + ", zipcode=" + zipcode + ", profileStatus=" + profileStatus
+ "]";
}

}


customerProfile.jsp

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
<title>Login and Registration Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="Login and Registration Form with HTML5 and CSS3" />
<meta name="keywords"
content="html5, css3, form, switch, animation, :target, pseudo-class" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/demo.css" />
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/style.css" />
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/animate-custom.css" 
/>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/bootstrap.css" />
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/app.css" />
</head>
<body>
<div class="container">
<header>
<h1>
User List</span>
</h1>
</header>
<section>
<div id="container_demo">
<div id="wrapper">
<div>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>LOGIN</th>
<th>PASSWORD</th>
</tr>
</thead>
<tbody>
<c:forEach var="c" items="${customer}">
<tr>
<td>${c.id}</td>
<td>${c.loginId}</td>
<td>${c.password}</td>
<c:forEach var="x" 
items="${customer.customerProfileVO}">
<td>${x.firstName}</td>
</c:forEach>
<td><a href="/edit-user-${c.id}"
class="btn btn-success custom- 
width">edit</a></td>
<td><a href="/delete-user-${c.id}"
class="btn btn-danger custom- 
width">delete</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</section>
</div>
</body>
</html>

在嵌套的c:forEach中,您处于c变量的上下文中,而不是customer,因此将项引用更改为:

items="${c.customerProfileVO}">

最新更新