Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...