There is a method that returns answers using id .
@RequestMapping(value = "/getAnswerByQuestionId",method = RequestMethod.GET) public String getAnswerByQuestionId(ModelMap map,@RequestParam("id")int id){ List<Answer> findAllBYQuestionId=answerRepository.findAllByQuestionId(id); map.addAttribute("findAllAnswersByQuestionId",findAllBYQuestionId); map.addAttribute("addAnswer",new Answer()); return "answerResult"; } this method goes to JSP here
<spring:form action="/addAnswer" method="post" enctype="multipart/form-data" modelAttribute="addAnswer"> <c:forEach items="${findAllAnswersByQuestionId}" var="name"> ${name.text} <input type="hidden" value="${name.id}" name="questionId"> </c:forEach> <spring:textarea path="text"></spring:textarea> <input type="file" name="pict"> <input type="submit" value="add"> </spring:form> on the second line prints the result. In this JSP, under the result is a form for adding a response. When everything is ok - the answer is added, the data goes here.
@RequestMapping(value = "/addAnswer",method = RequestMethod.POST) public String addAnswer(@ModelAttribute("answer")Answer answer,@AuthenticationPrincipal UserDetails userDetails,@RequestParam("questionId")int id,@RequestParam("pict")MultipartFile[] files) throws IOException { File dir = new File(imageUploadPath); if (!dir.exists()) { dir.mkdir(); } for (MultipartFile file : files) { String picName = System.currentTimeMillis() + "_" + file.getOriginalFilename(); File picture = new File("D:\\bankSystem\\" + picName); file.transferTo(picture); answer.setImage(picName); answer.setUserUsername(userDetails.getUsername()); answer.setQuestionId(id); } answerRepository.save(answer); return "redirect:/getAnswerByQuestionId"; } Here, getAnswerByQuestionId added and goes back to this method, so that the user adds another answer or sees his answer. The problem is that when you go back to this method getAnswerByQuestionId an error occurs
request param id is not present It will say that they did not give id so that he could print the result. Is it possible to do so in order not to give an id and enter this JSP?