[英]getSourceClassName method in java logRecord gives null value
[英]JSP Input value To Java Method -> HttpServletRequest gives NULL value
大家好。 我有一個簡單的存儲頁面,它顯示數據庫中的所有產品。 我設置給他們每個人用唯一的名字來改變產品的數量。 當我想在 Java 方法中捕獲這個值時,它返回給我 null 。 你能幫我在這個文本輸入中正確地捕捉價值需要做些什么嗎?
Controller:
@Controller
public class StoragePageController extends HttpServlet {
@GET
@RequestMapping(value = "/storage/subamount/{id}")
public String substractTheAmountValue(@PathVariable("id") int id, Model model, HttpServletRequest request) {
String amount_req = request.getParameter("amount_sub_" + id);
System.out.println(amount_req);
return null;
}
}
JSP 片段:
<c:set var="licznik" value="${recordStartCounter }" />
<div align="center">
<table width="1000" border="0" cellpadding="6" cellspacing="2">
<c:forEach var="u" items="${productList }">
<c:set var="licznik" value="${licznik+1}" />
<tr onmouseover="changeTrBg(this)" onmouseout="defaultTrBg(this)">
<td align="right"><c:out value="${licznik }" /></td>
<td align="left"><c:out value="${u.description }" /></td>
<td align="left"><c:out value="${u.amount }" /></td>
<td align="center"><input type="text" name="amount_sub_${licznik}" id="amount_sub_${licznik}"></td>
<td align="center"><input type="button" value="Substract the value" onclick="window.location.href='${pageContext.request.contextPath}/storage/subamount/${licznik}'"/></td>
</tr>
</c:forEach>
</table>
You should be having your API controller like the one given below given that your UI is posting the data to your API / Controller (assuming you are using the latest version of Spring Boot). 您有一個@Get
映射,它不接受正文中的請求有效負載。
@RestController
public class StoragePageController {
@PostMapping(value = "/storage/subamount/{id}", produces = {"application/json"})
public String substractTheAmountValue(@PathVariable("id") int id, Model model) {
String amount_req = id;
System.out.println(amount_req);
return null;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.