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();
}
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();
}