gpt4 book ai didi

java - 单击 html 普通按钮调用 spring MVC Controller ?

转载 作者:行者123 更新时间:2023-11-29 03:28:01 25 4
gpt4 key购买 nike

我有一个按钮的jsp页面。单击按钮时,它调用了 Controller ,并且 Controller 必须显示相同的 jsp 页面。我该怎么做?

Controller .java

 @Controller
@RequestMapping("/status")
public class CheckController {


@RequestMapping(method = RequestMethod.GET)
public String loadDetails(ModelMap model) {


List<Data> details = // fetch data from database
model.addAttribute("details ", details );
return "Status";
}

}


Status.jsp
----------

<html>
<body>
<h2>Spring MVC and List Example</h2>

<c:if test="${not empty details}">
<c:forEach var="listValue" items="${details}">
<table border="1" cellspacing="1" align="center"
style="margin-top: 160px;">
<tr>
<th>Status</th>
<th>Message</th>
<th>Last Updated</th>
</tr>
<tr>
<td>OK</td>
<td>${listValue.message}</td>
<td>${listValue.lastChecked}</td>
</tr>
</table>
</c:forEach>
</c:if>
<button>Load</button> //on click of button controller has to be called and again same jsp has to be rendered
</body>
</html>

最佳答案

<button onclick="window.location.href='/status'">Load</button>

如果您的 jsp 有表单,您可以将表单提交到 action='/status' url

关于java - 单击 html 普通按钮调用 spring MVC Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19954040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com