Issue
I use thymeleaf, in a spring boot program
When an user click this link i want to goto a page
<td><a th:href="@{/editings/testament/} + ${testament.id}" target="_blank" rel="noopener noreferrer"><i class="bi bi-pencil-square"></i></a></td>
In my controller I have
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER') ")
@GetMapping(value = "/editings/testament/{testamentId}")
public String editTestament(Model model, @PathVariable Long testamentId) throws Exception {
....
model.addAttribute("testamentId", testament.getId());
model.addAttribute("testamentDocument", testament.getTestamentDocument());
...
return "starter";
}
Actually when User click the link that open another tab with the starter page...
How to avoid that
Solution
So the reason that the page is opening in a new tab is because of the target="_blank" attribute present on the a tag.
If you remove this, you should be all set. The controller shouldn't need to be edited to make this happen. Here is a resource to read more: https://www.w3schools.com/tags/att_a_target.asp
Hope you're having a good day!
Answered By - Tyler Prill
Answer Checked By - Cary Denson (JavaFixing Admin)