i am using logic:iteraror tag to display data from a arraylist
i am usign like this
first i set the data in action file like this
request.setAttribute("userdetails",userdetails);
in the jsp i am usign like this
<logic:iterate id="maruref" name="userdetails" >
<br> <TD><bean:write name="maruref" /></TD>
</logic:iterate>
but in browser it is it is showing like this
[Ljava.lang.String;@13c9557
[Ljava.lang.String;@70898b
[Ljava.lang.String;@5606f3
[Ljava.lang.String;@1e2793d
but i want the exact data how can i display the excat data can any
one tell me how
thanx in advance
-
using bean:write to display data (7 messages)
- Posted by: ashok kumar
- Posted on: July 13 2005 07:47 EDT
Threaded Messages (7)
- using bean:write to display data by Amin Mohammed-Coleman on July 13 2005 08:48 EDT
- using bean:write to display data by ashok kumar on July 14 2005 01:41 EDT
- String v. String[] by Joe Wolf on July 14 2005 17:03 EDT
- Velocity by Alexandra Lei on July 25 2005 01:50 EDT
- To prevent parsing of special characters. by Conrad Seaman on August 12 2005 16:57 EDT
- Or the other way... by Conrad Seaman on August 12 2005 17:10 EDT
- display exact string in jsp by Rajendra Padhi on November 05 2011 00:29 EDT
-
using bean:write to display data[ Go to top ]
- Posted by: Amin Mohammed-Coleman
- Posted on: July 13 2005 08:48 EDT
- in response to ashok kumar
How about using JSTL tags to perfom the iteration. here is an example
[code]
LinkedHashMap labels = new LinkedHashMap();
labels.put("Document Title", "Title");
labels.put("Summary","Summary" );
labels.put("Product", "Prod");
labels.put("Date", "Date");
labels.put("Score", "Score");
labels.put("Document key", "docKey");
session.setAttribute("labels", labels);
[/code]
Then use JSTL tags to access this:
[code]
<c:forEach var="label" items="${labels}">
<c:out value="${label.key}"/> //prints the keys from
the hashmap
<c:out value="${label.value}"/>
</c:forEach>
[/code]
For your example it would be like this:
[code]
request.setAttribute("userdetails",userdetails);
<c:forEach var="userDetail" items="${items}">
<c:out value="${userDetail}"/>
</c:forEach>
[/code]
I've used struts custom tags but I prefer to use JSTL tags and they are more powerful.
If you wish to continue using struts tags then please send more information about what is contained in the arraylist.
Thanks -
using bean:write to display data[ Go to top ]
- Posted by: ashok kumar
- Posted on: July 14 2005 01:41 EDT
- in response to Amin Mohammed-Coleman
thanx for ur reply as you said i added the follwoing code
this is java code in action class
request.setAttribute("userdetails",userdetails);
userdetails contains data from a table
in the jsp
<c:forEach var="userdetail" items="${userdetails}">
<c:out value="${userdetail}"/>
</c:forEach>
but the output is not showing any thing...
whats wrong in the above code...How about using JSTL tags to perfom the iteration. here is an example[code]LinkedHashMap labels = new LinkedHashMap();labels.put("Document Title", "Title");labels.put("Summary","Summary" );labels.put("Product", "Prod");labels.put("Date", "Date");labels.put("Score", "Score");labels.put("Document key", "docKey");session.setAttribute("labels", labels);[/code]Then use JSTL tags to access this:[code]<c:forEach var="label" items="${labels}"> <c:out value="${label.key}"/> //prints the keys from the hashmap <c:out value="${label.value}"/></c:forEach>[/code]For your example it would be like this:[code]request.setAttribute("userdetails",userdetails); <c:forEach var="userDetail" items="${items}"> <c:out value="${userDetail}"/></c:forEach>[/code]I've used struts custom tags but I prefer to use JSTL tags and they are more powerful.If you wish to continue using struts tags then please send more information about what is contained in the arraylist. Thanks
-
String v. String[][ Go to top ]
- Posted by: Joe Wolf
- Posted on: July 14 2005 17:03 EDT
- in response to ashok kumar
Are the objects in your ArrayList Strings or String[]s?
If you just place String objects within your ArrayList, or at objects with pretty-printing toString() methods, your JSP should work just fine. -
Velocity[ Go to top ]
- Posted by: Alexandra Lei
- Posted on: July 25 2005 01:50 EDT
- in response to Joe Wolf
I came across similar problems several weeks ago. JSTL solves it well. But soon I found better tool: the Apache Velocity (http://jakarta.apache.org/velocity/). Velocity has a natual language grammar. The loop you mentioned can be done through #foreach()..#end No more tages anymore. Anyway, you can give a try. -
To prevent parsing of special characters.[ Go to top ]
- Posted by: Conrad Seaman
- Posted on: August 12 2005 16:57 EDT
- in response to ashok kumar
If your issue is the fact that the <bean> tag takes HTML code and writes it out as text rather than HTML then you can use the filter="true" setting and force the bean tag to filter html specific characters and convert them to their encoded counterpart. -
Or the other way...[ Go to top ]
- Posted by: Conrad Seaman
- Posted on: August 12 2005 17:10 EDT
- in response to ashok kumar
Sorry, I should also have said, you can set filter="false" so that the bean tag does not filter the html tags. This will cause it to write the text vebatim to the screen.
Example: if your data was
"something <br> something"
filter="true" would display in the browser as:
"something <br> something"
(or "something <br> something" behind the scenes)
filter="false" would display as:
"something
something"
(or "something <br> something" behind the scenes) -
display exact string in jsp[ Go to top ]
- Posted by: Rajendra Padhi
- Posted on: November 05 2011 00:29 EDT
- in response to ashok kumar
convert your data in to toString() by overriding toString() method of string class
i think this is help ful for you