我在春天的项目工作新的地方有两个控制器检查如果对象是在JSTL
AddOwnerForm.java & EditOwnerForm.java。将流转发到form.jsp
AddOwnerForm将新的Owner对象传递给jsp,而EditOwnerForm从db中获取Owner对象,然后将其传递给jsp。
下面是JSP代码。
Form.jsp
<%@ include file="/WEB-INF/view/include.jsp" %>
<%@ include file="/WEB-INF/view/header.jsp" %>
<c:choose>
<c:when test="${owner['new']}"><c:set var="method" value="post"/></c:when>
<c:otherwise><c:set var="method" value="put"/></c:otherwise>
</c:choose>
<h2><c:if test="${owner['new']}">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="${owner['new']}">
<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" %>
我不明白这个代码片断
<c:choose>
<c:when test="${owner['new']}"><c:set var="method" value="post"/></c:when>
<c:otherwise><c:set var="method" value="put"/></c:otherwise>
</c:choose>
A.如何,如果所有者对象是新JSTL标记检查。 “新”是JSTL的关键字吗?
B.为什么他们使用PUT方法编辑所有者为什么不POST?
所以你的意思是,如果我做 '所有者所有者=新的所有者(); model.addAttribute(owner);' 在我的控制器中 这是内部做'map.put(new,Owner)'? 地图来自哪里? – underdog
我也试过' '这不起作用 –
underdog
@ShivangSarawagi看我的编辑。另外,我不知道你的意思是不是working_。你期望发生什么? 'empty'检查是否有一个名为'owner'的属性。 –