servlet中ServletContext的使用

一:Servlet.java

String UserName=Request.getParameter("UserName");

UserName=new String(UserName.getBytes("ISO-8859-1"));

UsersDAO user=new UsersDAO();

ArrayList  users=user.queryByName(UserName);

request.setAttribute("users",users);

this.getServletContext().getRequestDispatcher("/Result.jsp").forward(request, response);

二:Result.jsp

ArrayList users=(ArrayList)request.getAttribute("users");

for(int i=0;i<users.size();i++) {

    Users user=(Users)users.get(i);

    user.getUserName();

}
posted on 2009-07-30 11:15  草原和大树  阅读(333)  评论(0编辑  收藏  举报