-3

I have a vector of objects in my servlet which I enumerate so that I can populate them in a jsp page one by one I imagine like this:

Enumeration<codes> ls = codes_found.elements();
            while (ls.hasMoreElements()){
                codes code=(codes)ls.nextElement();
                out.println("Code ID: "+code.getCode_id()+" Code Description: "+code.getCode_descr()+"<br/ >");
            }

Can someone tell me how can I populate them in jsp like this? Thanks

charilaos13
  • 543
  • 2
  • 7
  • 19
  • Just a piece of advice, before you go coding like this read a good book or a tutorial on whatever technology you are using. It will save you a lot of trouble... – Thihara Mar 28 '13 at 18:16
  • what is your problem?your code is right.Is it showing a different output?? – Biswajit Mar 28 '13 at 18:19
  • No :). Well don't I suppose to put them in an html tag or something? – charilaos13 Mar 28 '13 at 18:20
  • You must learn the basics. Start with [StackOverflow Servlets wiki](http://stackoverflow.com/tags/servlets/info) – Luiggi Mendoza Mar 28 '13 at 21:29
  • You really shouldn't name Java classes starting with lower case letters. `codes` should be named `Code` or something. You also might want to use a `Collection` instead of an `Enumeration`. – RustyTheBoyRobot Apr 03 '13 at 16:37

1 Answers1

0

I figured it out :). I put my Vector<codes> from my servlet in a session:

session.setAttribute("codes", codes_found);

Then I get the session-property with jstl:

<c:forEach items="${codes}" var="item">
    <input name="id" value="${item.code_id}">
    <input name="id" value="${item.code_descr}"></c:forEach>

I didn't know that with jstl and ${codes} you get the actual object. Now I know :).

charilaos13
  • 543
  • 2
  • 7
  • 19
  • Indeed, you could also set it as request attribute and forward to your page. This is covered in [StackOverflow Servlets wiki](http://stackoverflow.com/tags/servlets/info) (as stated in my comment on your question). – Luiggi Mendoza Mar 30 '13 at 17:20
  • Also, it would be good to check these two links: [Why is Java Vector class considered obsolete or deprecated?](http://stackoverflow.com/q/1386275/1065197) and [What does it mean to “program to an interface”?](http://stackoverflow.com/q/383947/1065197), from both links,you will know that it's better to use `List codes = new ArrayList();`. – Luiggi Mendoza Mar 30 '13 at 17:22