I am trying to read data from a table and display it to the user .
开发者_开发知识库Can anybody tell how to do it using struts 1.3 ?
Write an class extending Struts'
Action
class. This class pulls the data from Database as aList
. Pass this data as request attribute,request.setAttribute("myList", list)
. Return "success".In your
struts-config.xml
, map thisAction
class to a JSP on "success". The request will be forwarded to the JSP.In the JSP, get the list from request by
request.getAttribute("myList")
. Iterate through the list and print theList
.
You need to study this: http://struts.apache.org/1.x/userGuide/index.html
(Edit: Just noticed this is a 2 year old question)
Don't use the struts tags unless you NEED to. This can be accomplished with jstl/el. So on your Action class you would have something like this:
List<Map<?, ?>> listOfHashMaps = new ArrayList<Map<?, ?>>();
request.setAttribute("listOfHashMaps", listOfHashMaps);
In your jsp:
<c:forEach var="hashMap" items="listOfHashMaps">
${hashMap[someInteger]} <%-- To get the value associated with 'key' --%>
</c:forEach>
You can also access the keys/values with:
${hashMap.key}
${hashMap.value}
Respectively.
精彩评论