Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: JSTL - Array of objects?

  1. #1
    goochalba is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default JSTL - Array of objects?

    Hi,

    I am using JSTL in a JSP to access data from my MySQL database.
    Thus I am looping through doing a foreach:

    <c:forEach var="row" items="${rs.rows}">
    <c:set var="menuId" value="${row.id}"/>
    <c:set var="nextPage" value="${row.homePage}"/>
    <c:set var="promptText" value="${row.prompt}"/>
    <c:set var="menuType" value="${row.menuType}"/>
    </c:forEach>

    What I would like to do is capture this in an Array of objects.
    So that I can iterate through the list numerous times without
    having to requery the database each time.

    Thus is there a way to create an ArrayList of objects using JSTL?
    Or do I need to create the ArrayList outside of JSTL and then pass it
    to the JSTL?

    Thanks in advance!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: JSTL - Array of objects?

    Cross posted and adequately answered
    https://forums.oracle.com/forums/thr...readID=2425625

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    goochalba is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: JSTL - Array of objects?

    Actually I didn't get an answer to my question. I understand that I am doing it "wrong" there is a reason for that.
    Is it not possible to do what I am proposing is the answer I am looking for...

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: JSTL - Array of objects?

    Let me get this in a proper perspective. You want members on two forums to tell you how to do something the wrong way?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    goochalba is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: JSTL - Array of objects?

    Cross posting
    I was simply trying to build a rapid prototype for demonstration
    purposes. It doesn't need to be perfect just quick. I figured it out
    myself. And it works and works fine. It is not meant to be production
    code by any means. So maybe it is "wrong" and those who answered
    were not willing to help and rather bash me for wanting to do something
    "wrong". Thanks for all of your help!

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: JSTL - Array of objects?

    But because you are doing it wrong (as gimbal points out on OTN) it is taking you a lot longer than it would have done had you done it right, that is using a servlet for the processing. In the 12 hours since you posted this here you would have finished the job...several times over.
    Please do not ask for code as refusal often offends.

  7. #7
    goochalba is offline Member
    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0

    Default Re: JSTL - Array of objects?

    Wow this is the first and last time I ever use this board. I have used a lot of boards over the years and love
    it when know it alls like you guys have to belittle others to make yourselves feel better. How do you know
    how long it took me to finish? You must also be omniscient besides being a java expert wow congrats.
    And as I had built a series of JSTL's generating dyamic content from a database for a demo ripping all of that
    out and putting it in a servlet would have been faster how? Especially when this is new to me? Oh yea I could have
    started reading JSP books and/or doing tutorials that would have been a lot faster! When instead about another hour
    of googling I found what I was looking for and got it "working". Oh wait how can it be "working" when its "wrong"?
    I guess you guys will have to explain that to me as well lol

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: JSTL - Array of objects?

    Oh no, I can well believe you got it working, after all I can put screws into a wall with a hammer. Doesn't make it correct, though.

    And as for the 12 hours?
    That was the time between yoru first post and the one I replied to.

    This is a forum. We try and keep the information held here as correct as possible, which includes the correct ways that certain technologies should be used (best practice).
    Putting lots of logic into a JSP is not best practice...it is wrong in that respect.

    If we wanted to just be a code dump for any old tosh we'd probably rename it rose india.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. How to convert array of Objects into array of Strings
    By elenora in forum Advanced Java
    Replies: 1
    Last Post: 06-10-2011, 03:48 PM
  2. help with and array of objects
    By hoosierfan24 in forum New To Java
    Replies: 5
    Last Post: 01-23-2011, 02:45 AM
  3. Iterating over an array of objects in jstl
    By rahullahiri007 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-21-2010, 07:25 AM
  4. Displaying array values in jstl page
    By keshaba in forum Advanced Java
    Replies: 0
    Last Post: 04-23-2010, 10:00 AM
  5. How to access array stored in database through JSTL
    By saurabh.joshi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-19-2007, 01:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •