I have List<PostData>
with some posts for user in Servlet , how can i send this list to user's JSP page?? I need to split the server part and layout part.
Thanks.
This is my List:
public List<PostData> getPostforUser(String komy)
{
ArrayList<PostData> posts = new ArrayList<PostData>();
try {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from posts where komy='"+komy+"'");
while(rs.next())
{
PostData postdata = new PostData();
postdata.setId(rs.getInt("id"));
postdata.setOtkogo(rs.getString("otkogo"));
postdata.setKomy(rs.getString("komy"));
postdata.setText(rs.getString("text"));
postdata.setDate(rs.getString("'date'"));
posts.add(postdata);
}
}catch (SQLException e) {
e.printStackTrace();
}
return posts;
}
All is work, i made Connections and another things below.
Use request scope attribute, then you can access it with JSP EL via
${postforUser}
.You can set the list in your attribute and loop throught it on ur jsp.
In your jsp:
Without jstl, would be something like this: