0

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 ?

2 Answers 2

2
  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

Sign up to request clarification or add additional context in comments.

1 Comment

I am using a HashMap to store the data from a row . Then i am adding this HashMap to an ArrayList . How to iterate the ArrayList Of HashMaps in my jsp page using <logic:iterate > ??
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.