views:

30

answers:

2

I have a sql statement that pulls infomration about tagnum's for individual pidm's. Every pidm can have multiple tagnum's so I am dropping the information into an arraylist. I want to display the contents of this arraylist in a dropdown box on a html page.

Here is the code for the arraylist:

       <table style="border:transparent" style="width:100%">
            <tr>
             <td style ="width: 300px;">
             <select style="width:150px;"tabindex="5" name="Tag">
                 <option></option>
<%} rscheck.close();
     ResultSet rsTagCheck = stmt.executeQuery("SELECT PARKING.XKRPRMT.XKRPRMT_PIDM, PARKING.XKRPRMT.XKRPRMT_STATUS, PARKING.XKRPRMT.XKRPRMT_EXPIRE_YR, PARKING.XKRPRMT.XKRPRMT_TAG FROM PARKING.XKRPRMT WHERE XKRPRMT_PIDM ='" + BannerID + "'");

     while (rsTagCheck.next()){
            ArrayList<String> myTag = new ArrayList<String>();
            myTag.add(rsTagCheck.getString("XKRPRMT_TAG"));         
%>              
                  <option><%= myTag.get(0) %></option>
             </select>
             </td>

I can get the first element to show in the drop down box, but anything after that show an outofbounds exception. I want to know how to display ALL of the information in the arraylist.

@Pointy I did that and all I got was this:

alt text

It put the first one in there, but the rest would not populate!!

+2  A: 
Pointy
@Pointy I tried that and I posted the image in the question. It didn't populate past the first tagNum!!! The rest diplayed outside of the dropdown box.
gary A.K.A. G4
@gary: You should print the `</select>` only *after* the `while` loop, not inside. Further, your JSP/JDBC code as it is in the question is recipe for future trouble. I strongly recommend to put everything aside and get yourself through a *decent* JSP/Servlet/JDBC book/tutorial.
BalusC
@BalusC is correct - scriptlet code like that is a terribly outdated way of writing JSP pages.
Pointy
+1  A: 

Don't use scriptlets, use jstl tags and in this case

<c:forEach var="myTag" items="${rsTagCheck}">

and

<c:out value="${myTag.getString('XKRPRMT_TAG')}" />

Actually looking again at your code, I would not put the db query in a scriptlet! DB access should not be done here, pass the resultsets to jsp from servlet, and loop through data using jstl.

NimChimpsky
To expand on this answer, here's a [link](http://stackoverflow.com/questions/3177733/howto-avoid-java-code-in-jsp-files).
BalusC