Hi everybody,
I am not able to solve my problem with the select tag.
I need to populate the select tag with the elements of a field in a table of my database.
Now,I am just developing a very simple application where I just want to show the result of the select tag.
So I wrote TestForm.java that is my ActionForm class like this:
class TestForm extends ActionForm
{
public
String username;
public String getUsername() {
return username;
}
public void setUsername(String string) {
username=string;
}
public TestForm() {
super(); }
public ActionMapping execute(....) {......}
The code of my Action class is:
class
Test extends Action
{
private final static String SUCCESS="success";
private ArrayList users = new ArrayList();
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest req,HttpServletResponse resp)
throws Exception {
HttpSession session = req.getSession(true);
users = getUsers();
if (users != null)
session.setAtttribute("usersList"users);
return mapping.findForward(SUCCESS);
}
public ArrayList getUsers() {
String sql;
ArrayList test = new ArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DBname?user=username&password=password");
sql = "SELECT DISTINCT(username) FROM table";
Prepared statement = con.prepareStatement(sql);
ResultSet rs = statement.executeQuery();
while (rs.next()) {
test.add(rs.getString(1));
}
return test;
}
<catch {.....}
}
In my struts-config.xml file I have this code:
<form-beans>
<form-bean type="com.myapp.struts.TestForm" name="TestForm" />
</form-beans>
.....
<action-mapping>
<action type="com.myapp.struts.TestForm" path="/test" />
</action-mapping>
In the file index.jsp I use this code to use the <html:select> tag:
<logic:iterate id="test" collection="usersList" scope="session" type="com.myapp.struts.TestForm">
<html:select name="test" property="username" styleClass="dropdown">
<html

ptions name="test" property=username">
</html:select>
</logic:iterate>
when I run the application I get this error:
javax.servlet.ServletException:Cannot create iterator for this collection
How can I solve this problem?
Thanks,
Mattia