Reputation: 2293
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 ?
Upvotes: 0
Views: 3239
Reputation: 839
(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.
Upvotes: 0
Reputation: 55856
Write an class extending Struts' Action
class. This class pulls the data from Database as a List
. Pass this data as request attribute, request.setAttribute("myList", list)
. Return "success".
In your struts-config.xml
, map this Action
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 the List
.
You need to study this: http://struts.apache.org/1.x/userGuide/index.html
Upvotes: 2