我是 JSP 的新手,对将值从 Servlet 传递到呈现的 JSP 页面有一些疑问。
目前,我从表中获取参与者列表,并在请求对象中创建一个新属性并在我的 JSP 页面中访问该对象。
有没有其他方法可以将值从 servlet 传递给 JSP?
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Im in actorsservlet");
Actors acrs = new Actors();
ArrayList<Actor> actorslist = null;
try {
actorslist = acrs.getactors();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Actor ac:actorslist)
System.out.println(ac.firstname);
request.setAttribute("actorslist", actorslist);
RequestDispatcher dispatcher = request.getRequestDispatcher("getactors.jsp");
//response.sendRedirect("getactors.jsp");
dispatcher.forward(request, response);
return;