Reputation: 445
Im having trouble showing what I put in my ArrayList on JSP. The items in the list are taken from a Database in a Java class and then are shown in the JSP. Ive tried using the c:forEach but I still dont get it that much. Im new to JSP and Im trying not to use the scriplets. Thats why I do everything over my Java class. Also so that you got an idea on how it works, the admin chooses to see the whole database of the users, so it chooses on a option radio button tag, goes to a JSP page where it evaluates what the admin wants to see and forwards to the other page where the Arraylist must be shown. I call the function of the List in the JSP page that forwards to the JSP that shows the Database. I dont know if thats the correct way. Thanks!
This is the JAVA class
public List<administration> fullList() throws Exception{
List<administration> result = new ArrayList<administration>();
try{
Class.forName("com.mysql.jdbc.Driver");
connectMe = DriverManager.getConnection(url+dbName, userNameDB, passwordDB);
String query = "SELECT \n" +
" ControlAccess.UserName, \n" +
" ControlAccess.Pass, \n" +
" Users.First_Name,\n" +
" Users.Last_Name, \n" +
" UserInfo.Age, \n" +
" UserInfo.Country,\n" +
" UserInfo.Address,\n" +
" UserInfo.ZipCode,\n" +
" Sessions.Matrix1,\n" +
" Sessions.Matrix2,\n" +
" Sessions.Result,\n" +
" FilePath.LocationFiles\n" +
" FROM MatrixUsers.UserInfo \n" +
" INNER JOIN MatrixUsers.Users\n" +
" ON UserInfo.idUserInfo = Users.idUsers\n" +
" INNER JOIN MatrixUsers.ControlAccess \n" +
" ON ControlAccess.idControlAccess = UserInfo.idUserInfo\n" +
" INNER JOIN MatrixUsers.Sessions \n" +
" ON Sessions.idSessions = ControlAccess.idControlAccess\n" +
" INNER JOIN MatrixUsers.FilePath \n" +
" ON FilePath.idFilePath = Sessions.idSessions";
selectUsers = connectMe.prepareStatement(query);
selectUsers.executeQuery();
while(results.next()) {
administration admin = new administration();
admin.setUserName(results.getString("UserName"));
admin.setPassword(results.getString("Pass"));
admin.setFirstname(results.getString("First_Name"));
admin.setLastname(results.getString("Last_Name"));
admin.setAge(results.getInt("Age"));
admin.setCountry(results.getString("Country"));
admin.setAddress(results.getString("Address"));
admin.setZipcode(results.getInt("ZipCode"));
admin.setMatrix1(results.getString("Matrix1"));
admin.setMatrix2(results.getString("Matrix2"));
admin.setResult(results.getString("Result"));
admin.setLocation(results.getString("LocationFiles"));
result.add(admin);
}
results.close();
connectMe.close();
}catch(Exception e) {
e.printStackTrace();
}
return result;
}
This is how Im trying to show in the JSP:
<table>
<c:forEach var="admin" items="${admin.fullList()}">
<tr>
<td>${admin.username}" </td>
<td>${admin.password} </td>
<td>${admin.firstName} </td>
<td>${admin.lastName} </td>
<td>${admin.age} </td>
<td>${admin.country} </td>
<td>${admin.address} </td>
<td>${admin.zipcode} </td>
<td>${admin.Matrix1} </td>
<td>${admin.Matrix2} </td>
<td>${admin.Result} </td>
<td>${admin.location} </td>
</tr>
</c:forEach>
</table>
Upvotes: 0
Views: 272
Reputation: 308
plz try like this
<c:if test="${not empty result}">
<c:forEach var="e" items="${result}" >
<c:out value="${e.username}"/>
</c:forEach>
</c:if>
here i am iterating the list and the username by using c:out.
Upvotes: 1