开发者

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 ?


  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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜