0

我正在尝试从表中读取数据并将其显示给用户。

谁能告诉如何使用 struts 1.3 做到这一点?

4

2 回答 2

2
  1. 编写一个扩展 Struts 类的Action类。此类从数据库中提取数据作为List. 将此数据作为请求属性传递request.setAttribute("myList", list)。返回“成功”。

  2. 在您的struts-config.xml中,将此类映射Action到“成功”的 JSP。该请求将被转发到 JSP。

  3. 在 JSP 中,从 request by 获取列表request.getAttribute("myList")。遍历列表并打印List.

你需要研究这个:http ://struts.apache.org/1.x/userGuide/index.html

于 2011-02-26T17:41:36.477 回答
0

(编辑:刚刚注意到这是一个 2 岁的问题)

除非您需要,否则不要使用 struts 标签。这可以通过 jstl/el 来完成。所以在你的 Action 课上你会有这样的东西:

List<Map<?, ?>> listOfHashMaps = new ArrayList<Map<?, ?>>();
request.setAttribute("listOfHashMaps", listOfHashMaps);

在你的jsp中:

<c:forEach var="hashMap" items="listOfHashMaps">
    ${hashMap[someInteger]} <%-- To get the value associated with 'key' --%>
</c:forEach>

您还可以通过以下方式访问键/值:

${hashMap.key}
${hashMap.value}

分别。

于 2013-04-18T01:09:47.317 回答