我写了以下代码:
动物.java
package com.MyPack;
public class Animal
{
private String name;
/* getter and setter methods */
}
动物园.java
package com.MyPack;
public class Zoo
{
private String address;
private Animal animal;
/* Getter and Setter Method */
}
JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="animal" class="com.MyPack.Animal" scope="request">
<jsp:setProperty name="animal" property="name" value="Tiger" />
</jsp:useBean>
<jsp:useBean id="zoo" class="com.MyPack.Zoo" scope="request">
<jsp:setProperty name="zoo" property="address" value="Bannerghatta" />
<jsp:setProperty name="zoo" property="animal" value="${animal}" />
</jsp:useBean>
<jsp:getProperty name="zoo" property="${zoo.address}" />
</body>
</html>
我正在使用 EL 打印地址,我正在尝试使用动物类打印名称,${zoo.animal.name}
但它会导致错误。