本文介绍了调用不带正斜杠的URL最终会导致webapp文件夹struts2中的index.jsp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里的人们的帮助下,我设法使我的项目调用不带后缀.htm的程序包的默认操作.但是,如果我调用不带正斜杠的URL,则请求最终会到达webapp文件夹内的index.jsp.

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>

如果我调用http://someurl/someproject/secured/,则会执行操作,但是调用URL http://someurl/someproject/secured最终会导致文件index.jsp.

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.

该怎么办?谢谢

推荐答案

在调用http://someurl/someproject/secured url时,将secured视为不带后缀的操作,因为您已配置了操作可以具有空后缀(也是默认的顺便说一句).如果您希望此url重定向到/secured名称空间,则可以使用redirectAction结果声明secured操作,并在包中包含空或/名称空间.

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>

这篇关于调用不带正斜杠的URL最终会导致webapp文件夹struts2中的index.jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:45