Domanda

I am using the Struts2 framework and trying to get it to return to a specific section id on a page. Currently, it throws an error when I try to do the following:

<struts>
<constant name="struts.devMode" value="false"/>

<package name="default" namespace="/" extends="struts-default">

    <action name="default">
        <!--suppress Struts2ModelInspection -->
        <result type="redirectAction">index.jsp</result>
    </action>

    <action name="sendEmail" class="com.brickhouse.action.EmailAction">
        <result name="success">index.jsp#contact</result>
    </action>

    <action name="sendNewsletter" class="com.brickhouse.action.NewsletterAction">
        <result name="success">index.jsp</result>
    </action>

</package>

Of course, if I remove the hashtag and just let the "sendMail" action return to regular index.jsp as opposed to index.jsp#contact it works fine.

The section id that I am trying to return is contact.

<section id="contact">
    <div class="container">
       . . . .
    </div>
</section>

Any thoughts?

È stato utile?

Soluzione

You should not use a # sign as the dispatcher result, because dispatcher doesn't change URL the request is forwarded to. The resource with such name couldn't be found. Instead you can use it to build the URL or retuning a redirect result type to skip to the section (the last is never used). For example

<s:url var="skipToContact" value="#contact"/>
<s:a href="%{#skipToContact}">Skip to Contact</s:a>
...
<section id="contact"></section>

will skip to the section when you click on it. Make sure the section is not at the end of the document, i.e. the height from the section to the end of document is greater than a browser window height.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top