【发布时间】:2013-09-04 20:14:46
【问题描述】:
我想从 servlet 到 jsp 的 LinkedHashMap 键中获取员工姓名。
我在 java 类 View.java 中有这段代码
LinkedHashMap<Employee, LinkedHashMap<Skill, String>>() employeeSkills = new LinkedHashMap<Employee, LinkedHashMap<Skill, String>>();
Class View 为employeeSkills 提供了setter 和getter。
Class Employee 具有带有 setter 和 getter 的 name 和 id 属性。
JSP 代码:
< c:forEach var="employeeSkills" items="${employeeSkills}" >
<td>${employeeSkills.key.name}</td>
</c:forEach>
但我得到了这个错误
javax.el.PropertyNotFoundException:属性“名称”在 java.lang.String 类型上不可读
员工类:
class Employee{
String id;
String name;
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
public Employee(String id, String name) {
super();
this.id = id;
this.name = name;
}
}
【问题讨论】:
-
我不知道你为什么需要豆子。
-
我正在做一个大项目,他们已经是 bean 我想要一个数据结构,每个员工都有几个技能有没有更好的结构?
-
然后将 em 关联到员工对象。
-
你能显示
Employee类的代码吗? -
如何将 Map 传递给 JSP?