Hello! There was such a problem. I have a jsp page on which a form for adding an item and a list with all the items. I deduce the entire list like this: in the controller, I put a list of objects in the model and on the page I output it using jstl:
<table border=2 bgcolor="#C1CDCD" id="subjectsTableResponse"> <tr> <td align="center"><B>Предмет</B></td> </tr> <c:forEach items="${subjectList}" var="subject"> <c:if test="${subject.deleted eq false}"> <tr> <td align="center">${subject.title}</td> <td align="center"> <a href="<c:url value='/subject/update/${subject.id}' />">Редактировать</a> </td> <td align="center"> <a href="<c:url value='/subject/delete/${subject.id}' />">Удалить</a> </td> </tr> </c:if> </c:forEach> </table> Please note that in the reference to editing and deleting an object in curly brackets, the id of the item is displayed, on which you can later edit the item or delete it.
Here is my script, which adds an item to the list:
$(document).ready(function () { $('#saveSubject').submit(function (e) { $.post('/university/subjectAdd', $(this).serialize(), function (subject) { $('#subjectsTableResponse').last().append( '<tr>' + '<td align=\"center\">' + subject.title + '</td>' + '<td align=\"center\">' + '<a href=\"<c:url value=\'/subject/update/{'+subject.id+'}\'/>">' + 'Редактировать' + '</a>'+'</td>'+ '<td align=\"center\">' + '<a href=\"<c:url value=\'/subject/delete/{'+subject.id+'}\'/>">' + 'Удалить' + '</a>'+'</td>'+ '</tr>' ); }); }); }); When I just try to edit an object or delete, everything is OK, the controller pulls the id and performs the necessary operation, for example:
@RequestMapping(value = {"/student/delete/{id}"}, method = RequestMethod.GET) public ModelAndView studentDelete(@PathVariable Long id){ Student student = studentService.findById(id); student.setDeleted(true); studentService.update(student); return new ModelAndView(new RedirectView("/university/students")); } Now the crux of the problems. When I just added a new item to the list and decided to edit or delete it immediately (that is, without reloading the page), an error would read as follows:
Not allowed to load local resource: file:///C:/url%20value='/subject/delete/%7B160%7D'%3E%3C/a%3E If, I reload the page, then everything works out ok, apparently the controller itself converts to the desired form.
The very question, how to fix?)
'<a href="/subject/update/' + subject.id + '">Редактировать</a>'- Sergey Gornostaev