Java 在SpringWeb应用程序中登录后自动提交
我正在为在线航班预订创建Spring MVC web应用程序。这是一个初学者项目,我的问题可能太长了。我删除了不必要的代码。在这里,我创建了一个包含航班信息的jsp页面Java 在SpringWeb应用程序中登录后自动提交,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我正在为在线航班预订创建Spring MVC web应用程序。这是一个初学者项目,我的问题可能太长了。我删除了不必要的代码。在这里,我创建了一个包含航班信息的jsp页面 flightInfos.jsppage <table> <thead> <tr> <th>Flight No</th> <th>Flight destination</th>
flightInfos.jsp
page
<table>
<thead>
<tr>
<th>Flight No</th>
<th>Flight destination</th>
<th>Flight origin</th>
<th>Book now</th>
</tr>
</thead>
<tbody>
<form:form action='/flight-demo/flight-reservation.html'>
<c:forEach items="${flightInfos}" var="flightInfo">
<tr>
<td>${flightInfo.flightNo}</td>
<td>${flightInfo.destination}</td>
<td>${flightInfo.origin}</td>
<td><input type="submit" value="Book now"></td>
</tr>
</c:forEach>
</form:form>
</tbody>
</table>
然后,在用户登录到系统后,它会将用户重定向到flightreservation.jsp
页面
flightreservation.jsp
<form:form modelAttribute="reservation">
<c:if test="${param.ok eq true}">
<div class="alert alert-success" role="alert">Registration successful.</div>
</c:if>
<label for="customerName"> Name </label>
<form:input path="customerName"/>
<label for="flightInfo"> Flight No </label>
<form:input path="flightInfo" />
<input type="submit" value="Save" />
</form:form>
我的问题是,当我点击BookNow按钮时,它会检查用户是否已登录;如果记录,应显示
航班预订
页面。但是,当我单击BookNow按钮时,它会显示并自动将空值插入数据库中的航班预订表中。我怎样才能避免这种情况?我只是一个初学者,希望使用springmvc
。非常感谢您的帮助。我认为您需要配置web.xml。
是否定义了spring安全过滤器链?
是的,我已经定义了它。筛选和映射。为什么要使用modelAttribute@ModelAttribute(“保留”)总是在每个请求之前执行。我对用户注册也做了同样的事情。它工作得很好。如果不使用
@modeldattribute
我如何保存预订?我不明白@西蒙尼
<form:form modelAttribute="reservation">
<c:if test="${param.ok eq true}">
<div class="alert alert-success" role="alert">Registration successful.</div>
</c:if>
<label for="customerName"> Name </label>
<form:input path="customerName"/>
<label for="flightInfo"> Flight No </label>
<form:input path="flightInfo" />
<input type="submit" value="Save" />
</form:form>
@Controller
public class FlightResController {
@Autowired
private FlightReservationService reservationService;
@ModelAttribute("reservation")
public FlightReservation construct(){
return new FlightReservation();
}
@RequestMapping(value="/flight-reservation", method=RequestMethod.POST)
public String doReservation(@ModelAttribute("reservation") FlightReservation reservation){
reservationService.save(reservation);
return "redirect://flight-reservation.html?ok=true";
}
}