如何在 Struts 2 操作名称中允许斜线? [英] How to allow slashes in Struts 2 Action Names?

查看:27
本文介绍了如何在 Struts 2 操作名称中允许斜线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Struts 2 操作名称中启用斜线.我已经把它放在我的配置文件中:

I'm trying to enable slashes in Struts 2 action names. I've put this in my config file:

<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.action.extension" value=","/> 
    <constant name="struts.multipart.maxSize" value="2147483648" />
    <constant name="struts.enable.SlashesInActionNames" value="true"/>

    <package name="myApp" extends="struts-default">                         
        <action name="home" class="net.myapp.actions.HomeAction" method="execute">
            <result name="landing">/landing.jsp</result>
        </action>
        <action name="/ajax/foo" class="net.myApp.actions.ajax.FooAction" method="execute">
            <result name="success">/foo.jsp</result>
        </action>
    </package>        

</struts>

当我只访问这个应用程序的主页时,例如 http://localhost:8034/myApp,我正确地看到了主页.但是,如果我访问 http://localhost:8034/myApp/ajax/foo,我会收到错误消息:没有为动作名称 ajax/foo 映射的动作. 甚至虽然我在上面已经将它描述为第二个动作.

When I go to just the homepage of this app, e.g http://localhost:8034/myApp, I see the homepage correctly. But if I visit http://localhost:8034/myApp/ajax/foo, I get the error: There is no Action mapped for action name ajax/foo. even though I have described it above as the 2nd action.

我做错了什么?

推荐答案

我认为您还需要一个命名空间,所以 ajax 将是您的案例中的命名空间:

I'd say you need a namespace as well, so ajax would be the namespace in your case:

<package name="myApp" extends="struts-default" namespace="/ajax">    
  <action name="foo" class="net.myApp.actions.ajax.FooAction" method="execute">
     <result name="success">/foo.jsp</result>
  </action>
</package>

请注意,您可以在操作名称中使用斜杠,例如foo/bar,但不建议这样做,因为某些插件(例如对话插件)可能难以从像 /ajax/foo/bar.

Note that you could use slashes in your action names, e.g. foo/bar, but it's not advisable, since some plugins (e.g. the conversation plugin) might have difficulties to determine the namespace and action from a string like /ajax/foo/bar.

顺便说一句,错误信息说没有为动作名称ajax/foo映射的动作.,即struts寻找名为ajax/foo的动作,但你只有一个动作 /ajax/foo.

Btw, the error message says There is no Action mapped for action name ajax/foo., i.e. struts looks for an action named ajax/foo but you only have an action /ajax/foo.

这篇关于如何在 Struts 2 操作名称中允许斜线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆