我不做耶拿,但基本上你想遍歷com.hp.hpl.jena.query.ResultSet
和地圖信息爲List<RowObject>
,其中RowObject
是代表一個單列你想在一個HTML表格來顯示自己的模型類。映射後,將List<RowObject>
置於請求範圍內,並將請求轉發給JSP。
List<RowObject> results = getItSomeHow();
request.setAttribute("results", results); // Will be available as ${results} in JSP
request.getRequestDispatcher("page.jsp").forward(request, response);
然後在JSP中,使用JSTLc:forEach
遍歷List<RowObject>
,打印HTML表格。
<table>
<c:forEach items="${results}" var="rowObject">
<tr>
<td>${rowObject.someProperty}</td>
<td>${rowObject.anotherProperty}</td>
...
</tr>
</c:forEach>
</table>
更新根據您的其他答案,這裏是你如何能基礎上,耶拿的ResultSet
創建List<RowObject>
:
List<RowObject> results = new ArrayList<RowObject>();
while (rs.hasNext()) {
RowObject result = new RowObject();
QuerySolution binding = result.nextSolution();
result.setInd(binding.get("ind"));
result.setSomethingElse(binding.get("something_else"));
// ...
results.add(result);
}
,並按如下顯示它:
...
<td>${rowObject.ind}</td>
<td>${rowObject.somethingElse}</td>
...
這和我的答案基本相同,只是你在錯誤的地方打印。通常的做法是將結果顯示在JSP文件(視圖)中,而不是在servlet(Controller)中顯示。您需要創建一個模型並將其傳遞給視圖,如我的答案中所述。 – BalusC 2010-06-07 17:36:24