Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 带有条件和相对url的JSTL提交表单不起作用_Jsp_Jstl_Jsp Tags - Fatal编程技术网

Jsp 带有条件和相对url的JSTL提交表单不起作用

Jsp 带有条件和相对url的JSTL提交表单不起作用,jsp,jstl,jsp-tags,Jsp,Jstl,Jsp Tags,以下是用于创建或更新Post对象的表单(我也使用spring表单标记): 有什么问题,怎么解决 更新: 就行动而言,它应该是: <c:url value="/posts/" /> for create and <c:url value="/posts/${post.id}/" /> for update. 更新2: 对于行动,我可以使用: ${post.id == 0 ? '/posts/' : '/posts/${post.id}'} 但是,此注释在url中的“

以下是用于创建或更新Post对象的表单(我也使用spring表单标记):

有什么问题,怎么解决


更新:

就行动而言,它应该是:

<c:url value="/posts/" /> for create and 
<c:url value="/posts/${post.id}/" /> for update.
更新2:

对于行动,我可以使用:

${post.id == 0 ? '/posts/' : '/posts/${post.id}'}
但是,此注释在url中的“/”将与主机相对

也就是说,行动的形式是:

http://localhost/posts
虽然我希望它是:

http://localhost/context/posts
这就是为什么我会选择
,这将为我添加上下文

我希望这样:

${post.id == 0 ? '<c:url value="/posts/" />' : '<c:url value="/posts/${post.id}"/>'}
${post.id==0?'':'}

这不起作用。

在其他标记的属性中使用标记。
是嵌套的

试试这个:

 <sf:form method="${post.id == 0 ? 'post' : 'put'}" commandName="post"
          action="${post.id == 0 ? './posts/' : './posts/${post.id}'}">
    ...

    <input type="submit" value="Submit" name="submit" />
    or
    <a href="#" onClick="submit();">submit with link and JavaScript</a>

 </sf:form>


 <c:url value="${post.id == 0 ? './posts/' : './posts/${post.id}'}" var="url">
 </c:url>

 <a href="${url}">Huhu ein Link</a>

这也不能起作用,它又被嵌套了。请阅读。

操作如何?创建时它应该是
/posts/
,更新时它应该是
/posts/1/
。如何确定它是创建还是更新?
操作=“/${post.id==0?”post':'put'}/${post.id}”
这样做?
操作=“/posts/${post.id!=0?'1/':''}“
${condition?value\u if\u condition\u true:value\u else}
我必须使用c:url来构建将与应用程序上下文路径相关的操作
http://localhost/context/posts
${post.id == 0 ? '<c:url value="/posts/" />' : '<c:url value="/posts/${post.id}"/>'}
 <sf:form method="${post.id == 0 ? 'post' : 'put'}" commandName="post"
          action="${post.id == 0 ? './posts/' : './posts/${post.id}'}">
    ...

    <input type="submit" value="Submit" name="submit" />
    or
    <a href="#" onClick="submit();">submit with link and JavaScript</a>

 </sf:form>


 <c:url value="${post.id == 0 ? './posts/' : './posts/${post.id}'}" var="url">
 </c:url>

 <a href="${url}">Huhu ein Link</a>
> ${post.id == 0 ? '<c:url value="/posts/" />' : '<c:url
> value="/posts/${post.id}"/>'}