0
我工作的一個春天項目表導航混亂春天
從控制器AddForm.java的請求轉發到Form.jsp &的onsubmit從那裏回來到同一控制器。
代碼下面
Form.jsp
<%@ include file="/WEB-INF/view/include.jsp" %>
<%@ include file="/WEB-INF/view/header.jsp" %>
<c:choose>
<c:when test="${action eq 'addowner'}"><c:set var="method" value="post"/></c:when>
<c:otherwise><c:set var="method" value="put"/></c:otherwise>
</c:choose>
<h2><c:if test="${action eq 'addowner'}">New </c:if>Owner:</h2>
<form:form modelAttribute="owner" method="${method}">
<table>
<tr>
<th>
First Name:
<br/>
<form:input path="firstName" size="30" maxlength="80"/>
</th>
</tr>
<tr>
<th>
Last Name:
<br/>
<form:input path="lastName" size="30" maxlength="80"/>
</th>
</tr>
<tr>
<th>
Address:
<br/>
<form:input path="address" size="30" maxlength="80"/>
</th>
</tr>
<tr>
<th>
City:
<br/>
<form:input path="city" size="30" maxlength="80"/>
</th>
</tr>
<tr>
<th>
Telephone:
<br/>
<form:input path="telephone" size="20" maxlength="20"/>
</th>
</tr>
<tr>
<td>
<c:choose>
<c:when test="${action eq 'addowner'}">
<p class="submit"><input type="submit" value="Add Owner"/></p>
</c:when>
<c:otherwise>
<p class="submit"><input type="submit" value="Update Owner"/></p>
</c:otherwise>
</c:choose>
</td>
</tr>
</table>
</form:form>
<%@ include file="/WEB-INF/view/footer.jsp" %>
AddFormController代碼
@Controller
@RequestMapping("/owners/new")
@SessionAttributes(types = Owner.class)
public class AddOwnerForm {
private final Clinic clinic;
@Autowired
public AddOwnerForm(Clinic clinic) {
this.clinic = clinic;
}
@InitBinder
public void setAllowedFields(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}
@RequestMapping(method = RequestMethod.GET)
public String setupForm(Model model) {
Owner owner = new Owner();
model.addAttribute(owner);
model.addAttribute("action", "addowner");
return "owners/form";
}
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute Owner owner, SessionStatus status) {
System.out.println(owner.toString());
System.out.println("Inside AddOwner processSubmit method");
this.clinic.storeOwner(owner);
status.setComplete();
return "redirect:/forms/owners/" + owner.getId();
}
}
問題是在控制器中的setupForm方法轉發的形式流動到JSP但在JSP標記不通過動作,但提交流程返回到 processSubmit方法。誰能告訴我爲什麼?
請同時添加你的'@ Controller'類聲明。 –