Iterating over a Map instance, the Object is of type java.util.Map.Entry.
Map.Entry has two properties:
1) Key: The key under which the item is stored in the Map.
2) Value: The value associated with the key.
You have a ActionForm Name "EmpForm" and has a property named "empmap" that is declared as a Map and instantiated as a java.util.HashMap. In this Map, the key is a unique empId and the value is a String representing the empname;
Logic Iterate for Map
step 1. EmpForm code is
package com.techfaq.form;
public class EmpForm extends AactionForm {
private Map empmap;
public Map getEmpmap() {
return empmap;
}
public void setEmpmap(Map empmap) {
this.empmap = empmap;
}
}
step 2. your code is
Map empmap = new HashMap();
empmap.put("1","nick");
empmap.put("2","ram");
empmap.put("3","syam");
form.setEmpmap(empmap);
step 3. Logic Iterate Map: retrive values : This is the code in jsp to retrive the values from Map using logic:iterate
package com.techfaq.form;
public class MessageForm extends ActionForm{
private List messageList;
public List getMessageList() {
return messageList;
}
public void setMessageList(List messageList) {
this.messageList = messageList;
}
}
step 2. bean class : Message
package com.techfaq.beans;
public class Message {
private String longMsg;
private String createdBy;
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getLongMsg() {
return longMsg;
}
public void setLongMsg(String longMsg) {
this.longMsg = longMsg;
}
}
step 3. Logic Iterate List: retrive values : This is the code in jsp to retrive the values from List using logic:iterate