oigna oigna - 1 month ago 13x
MySQL Question

Pick values from mysql database ad populate select in struts2

I want to pick values from my database "Prodotti1" and populate a dropdown list with them in Struts2. I'm using

<sql:setDataSource var="ds" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/Prodotti1" user="root" password="root"/>
<sql:query dataSource="${ds}" var="result">
SELECT * from Producer;

<c:forEach var="row" items="${result.rows}">
<option value='<c:out value="${row.producer_name}"/>'>
<c:out value="${row.producer_name}"/></option>

I want to populate

<s:select label="Producer"
headerKey="-1" headerValue="--Select--"
name="" />

But i don't know what to put in
field. If i put
i got this error:

The requested list key '%{#result.row}' could not be resolved as a collection/array/map/enumeration/iterator type

How can i solve?


You might use #attr which will search the variable in all scopes.

<s:select label="Producer"
    headerKey="-1" headerValue="--Select--"
    name="producer" />