Java 为什么生成的URL中缺少我的参数值?
这是我的密码:Java 为什么生成的URL中缺少我的参数值?,java,url,struts2,param,Java,Url,Struts2,Param,这是我的密码: <s:iterator value="ChapterTreeList" id="chapterTree"> ... <s:url id="deployChaptersUrl" action="ajaxDeployChapter" includeContext="false"> <s:param name="nodeId"
<s:iterator value="ChapterTreeList" id="chapterTree">
...
<s:url
id="deployChaptersUrl"
action="ajaxDeployChapter"
includeContext="false">
<s:param
name="nodeId"
value="%{#chapterTree.nodeId}"/>
</s:url>
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}"
theme="simple"
method="POST">
</s:form>
...
</s:iterator>
我希望有多种形式,如下所示:
<form
id="deployChapters27623"
name="deployChapters27623"
action="/path/to/ajaxDeployChapter.action?nodeId=27623" <-- nodeId here
method="POST">
</form>
但我得到的是这样的表格:
<form
id="deployChapters27623"
name="deployChapters27623"
action="/path/to/ajaxDeployChapter.action" <-- nodeId is missing here
method="POST">
</form>
Struts 2.3.15.1我以前没有使用过Struts,不过我会冒险猜测一下
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}"
theme="simple"
method="POST">
</s:form>
应该是这个吗
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}?%{#chapterTree.nodeId}"
theme="simple"
method="POST">
</s:form>
我以前没有使用过Struts,不过我会冒险猜测一下
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}"
theme="simple"
method="POST">
</s:form>
应该是这个吗
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}?%{#chapterTree.nodeId}"
theme="simple"
method="POST">
</s:form>
POST HTTP方法将参数发送到请求正文中。这就是支持查询字符串中的参数的POST和GET之间的区别
所以,您甚至不应该尝试将查询字符串作为POST的一部分发送。反正也不行。如果您需要发送nodeId,您有2个选项
将其作为URL路径发送:/path/to/ajaxDeployChapter.action/27623。
创建隐藏表单字段nodeId并填充其值。
POST HTTP方法将参数发送到请求正文中。这就是支持查询字符串中的参数的POST和GET之间的区别
所以,您甚至不应该尝试将查询字符串作为POST的一部分发送。反正也不行。如果您需要发送nodeId,您有2个选项
将其作为URL路径发送:/path/to/ajaxDeployChapter.action/27623。
创建隐藏表单字段nodeId并填充其值。
以下是我解决问题的方法:
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}"
theme="simple"
method="POST">
<s:hidden name="nodeId" value"%{#chapterTree.nodeId}" />
</s:form>
以下是我解决问题的方法:
<s:form
id="deployChapters%{#chapterTree.nodeId}"
action="%{deployChapterUrl}"
theme="simple"
method="POST">
<s:hidden name="nodeId" value"%{#chapterTree.nodeId}" />
</s:form>
请为窗体使用隐藏字段,而不是带有参数的url。请参阅。也请使用var,而不是迭代器上不推荐使用的id,并尽快迁移到至少2.3.15.3,或更好的版本到2.3.16.1,因为从2.0.0到2.3.15.2,Struts版本会受到最近发现的安全问题的影响。请为隐藏字段使用标记。@AleksandrM我已找到根本原因。。。它不是Struts;请为窗体使用隐藏字段,而不是带有参数的url。请参阅。也请使用var,而不是迭代器上不推荐使用的id,并尽快迁移到至少2.3.15.3,或更好的版本到2.3.16.1,因为从2.0.0到2.3.15.2,Struts版本会受到最近发现的安全问题的影响。请为隐藏字段使用标记。@AleksandrM我已找到根本原因。。。它不是Struts;