Question

Here is my code:

<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>

I expect multiple forms like this one below:

<form 
     id="deployChapters27623"
     name="deployChapters27623"
     action="/path/to/ajaxDeployChapter.action?nodeId=27623" <-- nodeId here
     method="POST">
</form>

But instead I get forms like this:

<form 
     id="deployChapters27623"
     name="deployChapters27623"
     action="/path/to/ajaxDeployChapter.action" <-- nodeId is missing here
     method="POST">
</form>

Struts 2.3.15.1

Was it helpful?

Solution 3

Here is how I solved my issue:

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

OTHER TIPS

POST HTTP method sends parameters into the request body. This is the difference between POST and GET that supports parameters into the query string.

So, you just should not even try to send query string as a part of POST. It will not work anyway. If you need to send nodeId you have 2 options;

  1. send it as a URL path: /path/to/ajaxDeployChapter.action/27623.
  2. create hidden form field nodeId and populate its value.

I've not used Struts before, however I will hazard a guess.

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

Should it be this?

<s:form
     id="deployChapters%{#chapterTree.nodeId}" 
     action="%{deployChapterUrl}?%{#chapterTree.nodeId}"
     theme="simple"
     method="POST">
</s:form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top