我這樣做教程: http://proliferay.com/form-submit-in-spring-mvc-portlet/Spring MVC中的Portlet:形式不保存數據正確
一切正常,但在最後的部分。 在我的電腦上,客戶表單正確顯示。但是,如果我在表單中設置了客戶的詳細信息,那麼當我驗證表單時,客戶無法保存。 因此,下一個jsp(success.jsp)沒有找到保存的Customer客戶,因此顯示一個新數據爲空數據。
我的版本和教程的唯一區別是我必須從Maven構建項目,但這不應該改變任何東西?我可以得到正確答案: System.out.println(「\ ncustomer:」+ request.getAttribute(「customer」)+「\ n」);
這裏有class.jsp:
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%System.out.println("\ncustomer : " + request.getAttribute("customer") + "\n"); %>
<portlet:actionURL var="submitFormURL" name="handleCustomer"/>
<form:form name="customer" method="post" modelAttribute="customer" action="<%=submitFormURL.toString() %>"> <%-- onSubmit="displayParams"> --%>
<br/>
<table style="margin-left:80px">
<tbody>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName"></form:input></td>
</tr>
<tr>
<td><form:label path="middleName">Middle Name</form:label></td>
<td><form:input path="middleName"></form:input></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName"></form:input></td>
</tr>
<tr>
<td><form:label path="age">Age</form:label></td>
<td><form:input path="age"></form:input></td>
</tr>
<tr>
<td><form:label path="address">Address</form:label></td>
<td><form:input path="address"></form:input></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit Form">
</td>
</tr>
</tbody>
</table>
</form:form>
和相應的控制方法:
@ActionMapping(value = "handleCustomer")
public void getCustomerData(
@ModelAttribute("customer") Customer customer,
ActionRequest actionRequest, ActionResponse actionResponse,
Model model) {
log.info("#############Calling getCustomerData : post form validation##########");
System.out.println("\nModel : " + model);
//displays : "Model : {customer=null null,............."
System.out.println(customer.getFirstName());
System.out.println(customer.getLastName());
System.out.println(customer.getAddress());
actionResponse.setRenderParameter("action", "success");
model.addAttribute("successModel", customer);
}
任何想法是什麼能阻止它的工作? THX提前浮現在我的腦海裏
的聲明在哪裏? – libik
我相信他需要發送某種文章或者將回復發送給spring mvc主幹... –
對不起,在編輯中加入。我在之前的複製粘貼中錯過了它們。 –