0
Как передать массив объектов (Mcq [] mcq) из сервлета в JSP? Как я могу извлечь данные из массива объекта с помощью taglib в jsp?JSP: Как передать массив объекта из сервлета в JSP
КЛАСС:
public class Mcq {
private String question;
private String choice_1;
private String choice_2;
/* GETTERS AND SETTERS */
}
CONTROLLER:
String question, choice_1, choice_2;
Mcq[] mcq = new Mcq[100];
for(int i=0; i<mcqCount; i++){
question = request.getParameter("mcq-question-"+i);
choice_1 = request.getParameter("mcq-choice-"+i);
choice_2 = request.getParameter("mcq-choice-"+i);
mcq[i].setQuestion(question);
mcq[i].setChoice_1(choice_1);
mcq[i].setChoice_2(choice_2);
}
request.getSession().setAttribute("mcq", mcq);
RequestDispatcher dispatcher;
dispatcher = request.getRequestDispatcher("testpage.jsp");
dispatcher.forward(request, response);
HTML (testpage.jsp):
<body>
<h1>
Question: ${mcq.getQeustion()}
Choice-1: ${mcq.getChoice_1()}
Choice-2: ${mcq.getChoice_2()}
</h1>
</body>