Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

java - Calling a URL without forward slash end up to index.jsp in webapp folder struts2

With some help of the people here, I've managed to get my project to call the default actions of the packages without the suffix .htm. However, the request end up to index.jsp inside the webapp folder if I call the URL without the forward slash.

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <constant name="struts.action.extension" value="htm,," />
    <constant name="struts.objectFactory" value="spring" />  
    <constant name="struts.devMode" value="true"/>

    ...

    <package name="home" namespace="/secured" extends="default">
        <default-action-ref name="index" />

        <action name="index" class="homeAction" method="execute">
            <result name="success" type="tiles">home</result>
        </action>
    </package>
</struts>

Actions are executed if I call http://someurl/someproject/secured/, but calling the URL http://someurl/someproject/secured end up to the file index.jsp.

What to do? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you are calling http://someurl/someproject/secured url the secured is treated like action w/o suffix, because you have configured that actions can have empty suffix (which is also default btw). If you want that this url redirects to /secured namespace you can declare secured action with redirectAction result in package with empty or / namespace.

<package name="..." namespace="/" extends="struts-default">
  ...
  <action name="secured">
    <result type="redirectAction">
      <param name="actionName">index</param>
      <param name="namespace">/secured</param>
    </result>
  </action>
  ...
</package>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...