Reputation: 843
I want to populate data into table onclick a button in spring boot. That means I want get data from controller in a button call from a view page. I tried but my request mapping method will not called when I click button.
Here is my code I followed..
JSP page button
<button type="button" class="btn btn-info">
<i class="fas fa-search fa-2x"></i>
</button>
My table
<table class="table">
<thead>
<tr>
<th>LastName</th>
<th>FirstName</th>
</tr>
</thead>
<tbody>
<c:forEach items="${userInfoSelectedList}" var="user">
<tr>
<td>${user.firstname}</td>
<td>${user.lastname}</td>
</tr>
</c:forEach>
</tbody>
</table>
My Controller Code
@Controller
public class UserRightsController {
@RequestMapping(value="/user002222", method = RequestMethod.GET)
public String getid(Model model) {
List<UserInfoModel> userInfoSelectedList = dao.getUserInfos();
model.addAttribute("userInfoSelectedList", userInfoSelectedList);
return "userrights";
}
}
Problem is that how to call this method onclick button from jsp page. Please help me..?
Upvotes: 0
Views: 1168
Reputation: 871
You can call your GET endpoint in button like:
<button onclick="location.href='/user002222'">
Upvotes: 0
Reputation: 3677
You can write call to the web service using JavaScript code in your page:
<button type="button" class="btn btn-info" onclick="callWebService()">
Call Web Service in javascript code:
<script language="JavaScript">
function callWebService() {
....
}
</script>
Upvotes: 0