gpt4 book ai didi

java - spring web应用程序-html按钮-表单外的post方法-404错误

转载 作者:行者123 更新时间:2023-12-01 09:38:53 26 4
gpt4 key购买 nike

我尝试通过按钮“onClick”方法将 POST 请求从 JSP View 发送到 Controller ,但收到 404 错误,表明 RequestMapping 没有签名,这是为什么?

家庭 Controller :

@RequestMapping(value = "/showSelectedRequest/{id}", method = RequestMethod.POST)
public String loadRequestProducts(@PathVariable("id") int id, Model model) {

logger.debug("HomeController.RequestIdSelected() - Start");
logger.debug("HomeController.RequestIdSelected: id: " + id);
model.addAttribute("RequestIdSelected", id);

logger.debug("HomeController.RequestIdSelected() - Done");
return "/home";

}

首页.jsp:

<form action="${contextPath}/requestlist" method="post">    
<table class="table table-sm">
<thead class="thead-inverse">
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Show request
</th>
</tr>
</thead>

<c:forEach items="${requestDTOList}" var="requestDTO">
<tr>
<td>
${requestDTO.getId()}
</td>
<td>
${requestDTO.getName()}
</td>
<td>
<button class="btn btn-info" onclick="post(/showSelectedRequest/${requestDTO.getId()})">Query</button>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</td>
</tr>
</c:forEach>
</table>
</form>

最佳答案

当您有表单时,操作字段是当您单击“提交”类型的输入时将执行的操作字段。

作为解决方案,您可以按如下方式修改代码:

<form action="${contextPath}/showSelectedRequest/${requestDTO.getId()}" method="post">  
// Form elements ...
<input type="submit" value="Query" />
</form>

关于java - spring web应用程序-html按钮-表单外的post方法-404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38612111/

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