Lokesh Sah
Lokesh Sah

Reputation: 2293

Need to display data on a jsp page using struts 1.3

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

Answers (2)

int21h
int21h

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

Nishant
Nishant

Reputation: 55856

  1. 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".

  2. In your struts-config.xml, map this Action class to a JSP on "success". The request will be forwarded to the JSP.

  3. 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

Related Questions