我在日志中看到了一些NullPointerExceptions。所有例外都来自两个用户。弹簧控制器应该接收用户上传的表单对象。但它是空的。
这是表单的jsp代码:
<form method="POST" action="/events/${id}/tickets/checkout" id="checkout-info-form">
<label> Recipient Name <input id="recipient" type="text" name="recipient"></label>
<label class="address-row checkout-hidable"> Address Line 1 <input id="address1" type="text" name="addressLine1"> </label>
<label class="checkout-hidable"> Address Line 2 (optional) <input id="address2" type="text" name="addressLine2"> </label>
<label class="city-row checkout-hidable"> City <input type="text" id="city" name="city" placeholder="e.g. New York"> </label>
<label class="state-row checkout-hidable"> State <input type="text" id="state" name="state" placeholder="e.g. NY"> </label>
<label class="zip-row checkout-hidable"> Zip Code <input type="text" id="zip" name="zip" placeholder="e.g. 12345"> </label>
<label class="shipping-row">Shipping Method:</label>
<label class="shipping-method">
<input type="radio" name="shipping" value="usps_5days" id="shipping1">
<span>USPS 3-5 days shipping</span> $5.99
</label>
<label class="shipping-method">
<input type="radio" name="shipping" value="usps_1days" id="shipping2">
<span>USPS overnight shipping</span> $19.99
</label>
<c:set var="index" value="${0}"/>
<c:forEach items="${tickets}" var="ticket">
<input type="hidden" name="tickets[${index}]" value="${ticket.id}">
<c:set var="index" value="${index + 1}"/>
</c:forEach>
<c:remove var="index"/>
<input id="checkout-info-form-submit-button" class="btn-blue-large" type="submit" name="submitbutton" value="Next step">
</form>
这是我用来接收表单的模型对象:
public class CheckoutInfo implements Serializable {
private static final long serialVersionUID = 2585075011792338943L;
private String recipient;
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zip;
private String shipping;
private String[] tickets;
public CheckoutInfo() {
}
}
控制器:
@RequestMapping(value="/events/{eventId}/tickets/checkout", method=RequestMethod.POST)
public ModelAndView purchaseTickets(
@PathVariable("eventId") long id,
CheckoutInfo checkoutInfo,
RedirectAttributes redir,
@AuthenticationPrincipal User user) {
......
}
出现空指针异常,因为checkoutInfo为null。我不知道为什么会发生这种情况。我从未见过这种情况。而这仅来自我们的一些用户。我使用的是spring boot v1.2.3.RELEASE
如果有人能提供帮助,我感激不尽。