Do not judge strictly, the error in some trifles probably. There is view.jsp , a piece of code of interest here:

 <h1 class="tab"> View parts of details </h1> <c:if test="${!empty detailList}"> <table class="tab"> <tr> <th width="200">Name</th> <th width="80">Required</th> <th width="60">Count</th> <th width="60">Edit</th> <th width="60">Delete</th> </tr> <c:forEach items="${detailList}" var="detail"> <tr> <td>${detail.name}</td> <td>${detail.required}</td> <td>${detail.count}</td> <td><a href="<c:url value='/edit/${detail.name}/${page}/${detailList.size()}/${nameoflist}'/>">Edit</a></td> <td><a href="<c:url value='/delete/${detail.id}/${page}/${detailList.size()}/${nameoflist}'/>">Delete</a></td> </tr> </c:forEach> </table> </c:if> 

from the line with the link, and specifically this one:

 <td><a href="<c:url value='/edit/${detail.name}/${page}/${detailList.size()}/${nameoflist}'/>">Edit</a></td> 

Throws in the controller, specifically here:

 @GetMapping("/edit/{name}/{page}/{dlist}/{nameoflist}") public String edit(Model model, @PathVariable("name") String name, @PathVariable("page") int page, @PathVariable("dlist") int dlist, @PathVariable("nameoflist") String nameoflist){ Detail detailForEdit = serviceClassDetail.findByName(name); System.out.println(detailForEdit.getName() + detailForEdit.getId() + detailForEdit.getCount()); String str = serviceClassDetail.creatRedirectForEditDelete(dlist, nameoflist, page); model.addAttribute("detailForEdit", detailForEdit); return str; // "redirect:/[nameoflist]?=[page]" } 

From which redirect back to view. However, when I try to get this variable there, it is not there at all. Where and what am I doing wrong?

I try to view this data in a view simply:

 <c:if test="${detailForEdit != null}"> <a> ${detailForEdit.name} </a> </c:if> <a> detailForEdit = ${detailForEdit.name} </a> 

PS: description of logic: when I click on edit , I know which element I need to change, I switch to the controller-get-mapping, I pull out the data for changes and I want to substitute them into the view for subsequent changes, redirect it there, but there this data through the model does not come, why? Yes, sout in the controller is to verify that the data is really there.

  • I can be mistaken, but it's possible to redirect. Try to just send the user to the page without redirect. - not a Programmer
  • Does debugger show an item in the ModelView that you are adding? - GenCloud
  • In the debugger it shows that an element is added to the model, size = 1. If you just direct to the page, it adds the page after the current one, as a result, something like this gets out: localhost: 8080 / edit /% D0% 9C% D1% 8B% D1% 88% D1% 8C / 0/10 / view - vinsler

1 answer 1

Spring never does a redirect to a view; he uses the servlet dispatcher to refer to JSP. Because a JSP is a servlet that is automatically created after JSP compilation.

If you use a template engine like thymeleaf or freemarker, or velocity, then after processing the content is immediately written back and you don’t have to redirect one servlet to another.

How to use the template thymeleaf can be read here . As for the freemarker and / or velocity, you can read it here . That is, for a specific template engine, you must select the appropriate view resolver.

If you still want to continue using JSP for a view , then your problem is best solved by using <spring> tags instead of JSTL. Notice how the data is associated with the model.

If you do not understand the essence of using a redirect, then you should read here how and when you should, using the POST / GET methods for requests, develop the PRG pattern . This pattern is often used in CRUD applications, when the data from the form after add / edit is submitted to the controller and it redirects to another controller to view / show the added / changed data.