Discussions

Web tier: servlets, JSP, Web frameworks: using bean:write to display data

  1. using bean:write to display data (7 messages)

    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

    Threaded Messages (7)

  2. 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
  3. 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}">&nbsp;&nbsp;<c:out value="${label.key}"/> //prints the keys from the hashmap&nbsp;&nbsp;<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}">&nbsp;<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
  4. String v. String[][ Go to top ]

    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.
  5. Velocity[ Go to top ]

    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.
  6. 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.
  7. Or the other way...[ Go to top ]

    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)
  8. display exact string in jsp[ Go to top ]

    convert your data in to toString() by overriding toString() method of string class

    i think this is help ful for you