The following is form for create or upadte a Post object(I use the spring form tag also):
<sf:form method="<c:choose><c:when test="${post.id==0}">post</c:when><c:otherwise>put</c:otherwise></c:choose>" commandName="post">
Title:<sf:input path="title" /><sf:errors path="title" /><br />
Body:<sf:textarea path="body" cols="70" rows="6" /><sf:errors path="body" /><br />
</sf:form>
And when the post.id==0
,it means that this post is to be created while the method of the form should be "POST",otherwise it is updated and the method will be "PUT".
But the above code will cause exception:
org.apache.jasper.JasperException: /WEB-INF/jsp/posts/_form.jsp (line: 5, column: 41) Unterminated <sf:form tag
What's the problem,how to fix it?
update:
for the action it should be :
<c:url value="/posts/" /> for create and
<c:url value="/posts/${post.id}/" /> for update.
Then the finally action will be /appcontext/posts
or
/appcontext/posts/1
update2:
For action I can use :
${post.id == 0 ? '/posts/' : '/posts/${post.id}'}
However,this note the '/' in the url, it will be relatived to the host.
That's to say,the form action will be:
http://localhost/posts
While I want it be:
http://localhost/context/posts
That's why I perfer <c:url>
which will add the context for me.
And I want this manner:
${post.id == 0 ? '<c:url value="/posts/" />' : '<c:url value="/posts/${post.id}"/>'}
Which does not work.