Reputation: 71
I'm using struts2. Through my action, I get a Hashmap from a Resultset of java:
ArrayList<HashMap<Integer,Object>> customer = new ArrayList<HashMap<Integer,Object>>();
if(!(finalQuery.equals(""))){
ResultSet rsFinalQuery = conn.createStatement().executeQuery(finalQuery);
ResultSetMetaData md = rsFinalQuery.getMetaData();
int columnCount = md.getColumnCount();
while (rsFinalQuery.next()){
HashMap<Integer,Object> row = new HashMap<Integer,Object>();
for(int i=1; i<=columnCount; ++i){
row.put(i,rsFinalQuery.getObject(i));
}
biReport.add(row);
}
}
This is my action class:
public class Actionclass implements SessionAware {
private Data db;
private Map<String, Object> session;
ArrayList<HashMap<Integer,Object>> customer = new ArrayList<HashMap<Integer,Object>>();
public String execute() {
db = (Data) session.get("db");
this.customer = (ArrayList<HashMap<Integer, Object>>)
db.illustrateReport(this.reportID).get(1);
return "success";
}
public ArrayList<String> getColumnNames() {
return columnNames;
}
public void setColumnNames(ArrayList<String> columnNames) {
this.columnNames = columnNames;
}
public ArrayList<HashMap<Integer, Object>> getCustomer() {
return customer;
}
public void setBiReport(ArrayList<HashMap<Integer, Object>> biCustomer) {
this.customer = customer;
}
@Override
public void setSession(Map arg0) {
this.session = arg0;
}
}
And this is my jsp:
<html>
<head>
</head>
<body>
<TABLE>
<TR>
<s:iterator value="customer">
<option value='<s:property value="value" />'></option>
</s:iterator>
</TR>
</TABLE>
</body>
</html>
Now my issue is how can I display the table stored in my HashMap in jsp as a table using struts? I'm not using beans or HTTPservlet and I don't want to have java code in my jsp.
Would be great if you could help!
Upvotes: 4
Views: 1727
Reputation: 71
I finally solved it. This is the right code in the jsp file:
<tr>
<s:iterator value="customer">
<s:iterator value="top">
<td><s:property value="value"/> </td>
</s:iterator>
</s:iterator>
</tr>
Thank you everybody for your help!
Upvotes: 3