这是我的数据库查询功能
public static List<UserPass> selectAllUser() {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
List<UserPass> usersPass = new ArrayList<UserPass>();
String query = "select * from UserPass";
try{
ps = connection.prepareStatement(query);
rs = ps.executeQuery();
while(rs.next()){
UserPass users = new UserPass();
users.setUserName(rs.getString("user_name"));
usersPass.add(users);
}
return usersPass;
这是我的 UserPass 对象获取函数
public ArrayList<UserPass> getusernames(){
return usernames;
}
我的 servlet dopost 就是这样
request.setAttribute("users", UserPassDb.selectAllUser());
String forward = "/testpage.jsp";
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
我的显示jsp页面是
<form action="TestServlet" method="post">
<input type="submit">
</form>
<c:forEach var="user" items="${users}">
<c:out value="${user.usernames}"/>
</c:forEach>
UserPass 类
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package business;
import java.io.Serializable;
import java.util.ArrayList;
/**
*
* @author One
*/
public class UserPass implements Serializable {
public String username;
public String password;
public ArrayList<UserPass> usernames;
public UserPass(){
this.username ="";
this.password ="";
this.usernames = new ArrayList<UserPass>();
}
public void setUserName(String username) {
this.username = username;
}
public String getUserName(){
return username;
}
public ArrayList<UserPass> getusernames(){
return usernames;
}
public void setusernames(ArrayList<UserPass> a){
this.usernames = a;
}
}
尝试改变它告诉我财产不存在,据我所知。我肯定错了
提前致谢