我是JSP的新手,并且有一些关于将值从Servlet传递到呈现的JSP页面的问题。
目前,我从表中获取一个actor列表,并在请求对象中创建一个新属性,并在我的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;
答案 0 :(得分:0)