隐藏值在网络调用中但未到达 spring mvc 控制器
Hidden value is in network call but not reaching to spring mvc controller
将隐藏字段(开始和结束)从 JSP 传递到 Spring MVC 控制器,但它没有到达,在我的调试点,检查的值为空,但在完成调用后,这些可以在网络调用中清楚地观察到值。
为什么不使用 'rental' object
传递隐藏字段的值
JSP代码,
<body>
<center>
<table border="1">
<tr>
<th><h2>Name</h2></th>
</tr>
<c:forEach items="${vehicles}" var="e">
<tr>
<td>${e.vehicleName}</td>
</tr>
</c:forEach>
</table>
<br> <br>
<form:form action="bookVehicle.web" method="post"
modelAttribute="rental">
<form:select path="vehicle.vehicleId">
<form:option value="" label="-- Select" />
<form:options items="${vehicles}" itemValue="vehicleId"
itemLabel="vehicleName" />
</form:select>
<br>
<br>
<b>Enter userId </b>
<br>
<br>
<form:input path="user.email" />
<br>
<br>
<form:hidden path="start" value="${start}" />
<form:hidden path="end" value="${end}" />
<input type="submit" value="book" name="bookVehicleBtn" />
</form:form>
<br> <br> <a href="index.web">Return To Home Page</a>
</center>
</body>
@RequestMapping(value = "/bookVehicle.web", method = RequestMethod.POST, params = "bookVehicleBtn")
public String bookVehicle(Model model, @ModelAttribute("rental") Rental rental, BindingResult error) {
System.out.println(" inside controller ");
model.addAttribute("message", rentalService.proceedBooking(rental));
return "message";
}
请确保您的模型 class 字段(开始和结束)是字符串类型。
将隐藏字段(开始和结束)从 JSP 传递到 Spring MVC 控制器,但它没有到达,在我的调试点,检查的值为空,但在完成调用后,这些可以在网络调用中清楚地观察到值。 为什么不使用 'rental' object
传递隐藏字段的值JSP代码,
<body>
<center>
<table border="1">
<tr>
<th><h2>Name</h2></th>
</tr>
<c:forEach items="${vehicles}" var="e">
<tr>
<td>${e.vehicleName}</td>
</tr>
</c:forEach>
</table>
<br> <br>
<form:form action="bookVehicle.web" method="post"
modelAttribute="rental">
<form:select path="vehicle.vehicleId">
<form:option value="" label="-- Select" />
<form:options items="${vehicles}" itemValue="vehicleId"
itemLabel="vehicleName" />
</form:select>
<br>
<br>
<b>Enter userId </b>
<br>
<br>
<form:input path="user.email" />
<br>
<br>
<form:hidden path="start" value="${start}" />
<form:hidden path="end" value="${end}" />
<input type="submit" value="book" name="bookVehicleBtn" />
</form:form>
<br> <br> <a href="index.web">Return To Home Page</a>
</center>
</body>
@RequestMapping(value = "/bookVehicle.web", method = RequestMethod.POST, params = "bookVehicleBtn")
public String bookVehicle(Model model, @ModelAttribute("rental") Rental rental, BindingResult error) {
System.out.println(" inside controller ");
model.addAttribute("message", rentalService.proceedBooking(rental));
return "message";
}
请确保您的模型 class 字段(开始和结束)是字符串类型。