Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Where did you paste the code from? It uses the <em>rowsByIndex</em> property, so it is clearly meant for use with jstl tag (and it is written by someone who knew it). On the other hand, using two nested forEach clauses makes no sense in this context: you are going to end up with a separate option for each of the students data (name, last name, whatever), instead of a single option for a single student. It looks as if the original code was for a data grid of some kind, and has been modified without a trace of understanding.</p> <p>With all due respect, I share the view that you are not ready to write the application - and you are not going to learn much by trying, as you will soon come to harder and harder topics. If you are forced to continue the application, try dumping JSF and concentrate on JSP/JSTL, I believe it has less caveats for a beginner and it will make it easier for you to learn the basics of web applications.</p> <p>That said, the answer you are looking for is:</p> <pre><code>&lt;sql:setDataSource dataSource="jdbc/db" /&gt; &lt;sql:query var="students"&gt; select * from students &lt;/sql:query&gt; &lt;form action="student/studentQueryResponse.jsp"&gt; &lt;strong&gt;Select a student:&lt;/strong&gt; &lt;select name="studentID"&gt; &lt;c:forEach var="row" items="${students.rowsByIndex}"&gt; &lt;option id="&lt;c:out value="${row[0]}"/&gt;"&gt;&lt;c:out value="${row[1]}"/&gt;&lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt; &lt;input type="submit" value="submit" name="submit" /&gt; &lt;/form&gt; </code></pre> <p>You will have to substitute the sql query with your own, and you will have to register a datasource <em>jdbc/db</em> in your application server and in the <em>web.xml</em> file. Of course, you will also need a MySQL driver. I assumed that you willl need student's id and that it is the first column of your query.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload