Struts 2
  1. Struts 2
  2. WW-3355

s:form tag render action URL with query string incorrectly

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: 2.2.1
    • Component/s: Plugin - Tags
    • Labels:
      None

      Description

      Normally,

      <s:form action="%

      {'Simple?a=123&b=234'}

      ">

      would be rendered as:

      <form action="/mysite/Simple.action?a=123&b=234" ... >

      But if the ".action" suffix is omitted in the request URL,
      (e.g. http://localhost/mysite/Simple )
      it will be rendered as:

      <form action="/mysite/Simple" ... >

      The query string is not appended.

      In org.apache.struts2.dispatcher.mapper.DefaultActionMapper#getUriFromActionMapping(),
      query string is appended only in case that the extension is provided.

      1. DefaultActionMapper.java.diff
        1.0 kB
        Iwasa Kazmi
      2. DefaultActionMapper-WW-3355.patch
        2 kB
        Lukasz Lenart

        Activity

        Hide
        Iwasa Kazmi added a comment -

        Here is my patch to resolve this problem.
        Currently, the return value of the orig.getExtension() overrides the return value of the getDefaultExtension().
        So if the requested URI had no extension, the new extension will be null. (and query-string will not be added)

        I modified so that the default extension ("action") will be added if the requested URI had no extension.
        But it may causes compatibility issue.

        Show
        Iwasa Kazmi added a comment - Here is my patch to resolve this problem. Currently, the return value of the orig.getExtension() overrides the return value of the getDefaultExtension(). So if the requested URI had no extension, the new extension will be null. (and query-string will not be added) I modified so that the default extension ("action") will be added if the requested URI had no extension. But it may causes compatibility issue.
        Hide
        Lukasz Lenart added a comment -

        I checked it and if you specify empty extension like this
        struts.action.extension=
        you will get the same problem again.

        Maybe it will be better to move params.length() > 0 ... outside extension checking condition?

        right now:
        if (extension != null) {

        if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) {
        if (extension.length() > 0)

        { uri.append(".").append(extension); }
        if (params.length() > 0) { uri.append(params); }
        }
        }

        after:
        if (extension != null) {

        if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) {
        if (extension.length() > 0) { uri.append(".").append(extension); }

        }
        }
        if (params.length() > 0)

        { uri.append(params); }

        Patch provided

        Regards

        Lukasz

        Show
        Lukasz Lenart added a comment - I checked it and if you specify empty extension like this struts.action.extension= you will get the same problem again. Maybe it will be better to move params.length() > 0 ... outside extension checking condition? right now: if (extension != null) { if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) { if (extension.length() > 0) { uri.append(".").append(extension); } if (params.length() > 0) { uri.append(params); } } } after: if (extension != null) { if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) { if (extension.length() > 0) { uri.append(".").append(extension); } } } if (params.length() > 0) { uri.append(params); } Patch provided Regards – Lukasz
        Hide
        Lukasz Lenart added a comment -

        Done, patch applied! Thanks!

        Show
        Lukasz Lenart added a comment - Done, patch applied! Thanks!

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Iwasa Kazmi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development