我只收到一条评论,并且在发布新评论时它会更新,但我想查看发布的所有评论,我错在哪里?
评论小服务程序
String comment=request.getParameter("myTextarea"); //i stored myTextarea in string comment
ArrayList<String> al1 = new ArrayList<String>();
ArrayList emp_list =new ArrayList();
al1.add(comment);
emp_list.add(al1);
request.setAttribute("empList",emp_list);
String nextJSP = "/result.jsp";//goes to result.jsp
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
结果.jsp
<%
try{
int i=0;
if(request.getAttribute("empList")!=null)
{
ArrayList al3 = (ArrayList)request.getAttribute("empList");
Iterator itr = al3.iterator();
while(itr.hasNext()){
ArrayList empList = (ArrayList)itr.next();
String newcomment="";
try{
newcomment=(String)empList.get(i++);
}
catch(Exception e){
}
try{
out.println(newcomment);// i am getting only one comment here
}
catch(Exception e){
}
}
}
}//end of try block
catch(Exception e){
out.println(e);
}
%>