Hello, there are codes in jsp which allows you to add an answer to a question and see all the answers. In the database, the answer stores the question id. To see the answers there is such a method:
<c:forEach items="${findAllAnswersByQuestionId}" var="name"> ${name.text} <input type="hidden" value="${name.id}" name="questionId"> </c:forEach> The backend part doesn’t matter what happens there. The answer can be given through the question id. So when the program is launched in the browser, the question will appear when we click on this question This part of ${findAllAnswersByQuestionId} and the question id will be remembered then there is a form that adds the answer:
<spring:form action="/addAnswer" method="post" enctype="multipart/form-data" modelAttribute="addAnswer"> <spring:textarea path="text"></spring:textarea> <input type="file" name="pict"> <input type="submit" value="add"> </spring:form> at the top of line 3 there is such a code <input type="hidden" value="${name.id}" name="questionId"> here it will remember the id of the question and when we click on the add the answer in the database is saved under the corresponding question so As if we added an answer to a question that has 4 id answer, it saves itself and the question id in database. the problem is that if we add this code <input type="hidden" value="${name.id}" name="questionId"> in the loop and we will answer the question of which 4 id it saves in id under 16 id it This happens because every time it comes from all questions. If we don’t write code inside this cycle, then this part doesn’t work value="${name.id}" because we give this name from here, <c:forEach items="${findAllAnswersByQuestionId}" var="name"> can this be done so that this part <c:forEach items="${findAllAnswersByQuestionId}" var="name"> How did it become static so that it was accessible to the whole class?