喜每個人都可以在任何幫助我...如何將servelet數組列表傳遞給jsp表?
我想列出從數據庫和顯示所有的數據把jsp表
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession(true);
try {
Connection con=DataConnection.getconnection();
PreparedStatement pst;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
pst = con.prepareStatement("select * from [user]");
ResultSet rs = pst.executeQuery();
List<User> ee = new ArrayList<User>();
while (rs.next()) {
User e = new User();
e.setName(rs.getString(1));
e.setUserName(rs.getString(2));
e.setPass(rs.getString(3));
ee.add(e);
}
request.getSession().setAttribute("ee", ee);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/user.jsp");
rd.forward(request, response);
} catch (Throwable theException) {
System.out.println(theException);
}
}
這是我的代碼,它包含數組列表並通過它trought request.getSession()。setAttribute(「ee」,ee);
現在怎麼接取在JSP中這個值,它應該在從表 的顯示可以在任何給我的示例代碼此
嘗試在您的jsp頁面中: - 列表 ee = new ArrayList (); ee =(列表)request.getAttribute(「ee」); –
這是不可能的gaurav,因爲Sameer在會話中不在請求中設置了值。 –