为什么生成的URL中缺少我的参数值?

时间:2014-03-27 12:31:36

标签: java url struts2 param

这是我的代码:

<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

3 个答案:

答案 0 :(得分:2)

POST HTTP方法将参数发送到请求正文中。这是支持查询字符串中的参数的POSTGET之间的差异。

所以,你甚至不应该尝试将查询字符串作为POST的一部分发送。无论如何它都行不通。如果您需要发送nodeId,则有2个选项;

  1. 将其作为网址路径发送:/path/to/ajaxDeployChapter.action/27623
  2. 创建隐藏的表单字段nodeId并填充其值。

答案 1 :(得分: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>

答案 2 :(得分:1)

以下是我解决问题的方法:

<s:form
     id="deployChapters%{#chapterTree.nodeId}" 
     action="%{deployChapterUrl}"
     theme="simple"
     method="POST">
     <s:hidden name="nodeId" value"%{#chapterTree.nodeId}" />
</s:form>