我在ArrayList中设置这两个数组的数据,并将这个数组列表从servlet发送到jsp但是在jsp页面上,当我尝试打印这些名称和联系人时,只有姓氏和联系人打印三次。我不知道这个错误是在服务器端还是在客户端。
SetsAndGetsData tutor = new SetsAndGetsData();
List<SetsAndGetsData> alltutors = new ArrayList<SetsAndGetsData>();
String Names[3] = {"Alpha","Beta","Gemma"};
String contacts[3] = {"Contact_1","Contact_2","Contact_3"};
tutor.setNames(n);
tutor.setContact(contact);
alltutors.add(tutor);
request.setAttribute("tutors", alltutors);
RequestDispatcher req = request.getRequestDispatcher("/Test.jsp");
req.forward(request, response);
//Jsp side code Test.jsp
<%
List<SetsAndGetsData> alltutors = (ArrayList<SetsAndGetsData>)request.getAttribute("tutors");
for(SetsAndGetsData t: alltutors){
%>
<h1><%=t.getname() %></h1>
<h1><%=t.getcontact() %></h1>
<% } %>