Using a dash in Struts 2 action name

2019-08-10 09:47发布

问题:

I have the following action:

<action name="#dash_creds" class="AccountDashboardActionBean">
    <result name="success" type="stream">
        <param name="contentType">application/json</param>
        <param name="inputName">jsonInputStream</param>
    </result>
</action>

I want Struts to accept the # symbol in my URL or to ignore it, for now it does not call my action.

回答1:

The hash symbol is used to identify the "fragment" part of the URL; everything after the first # in a url is treated as part of the fragment and it is not sent to the server.

This means that an action name with a # in it will never be reached; if you call this from the browser:

http://domain.name/namespace/#dash_creds

your Struts application will see:

http://domain.name/namespace/

For the same reason, I don't think there's a way to make Struts "ignore it". Your action name should not include an hash.

See also these links:

  • http://en.wikipedia.org/wiki/Fragment_identifier
  • https://blog.httpwatch.com/2011/03/01/6-things-you-should-know-about-fragment-urls/


回答2:

The special character # is not allowed as a part of the action name. If you want to build url using the action name, you can use url tag.

<s:url var="url" action="" anchor="dash_creds"/>