Java/Struts2:如何从当前 url 获取操作名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20131602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:23:19  来源:igfitidea点击:

Java/Struts2: How to get action name from current url

javastruts2

提问by Dan

I am having a active page with its url like http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

我有一个活动页面,其网址如下 http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

Now i want get the action name(4th name after the sign /) i.e setuppageforwared.

现在我想获取操作名称(符号后的第 4 个名称/),即 setuppageforwared。

How to achieve this ? Please help me to know because i read many books of struts2 i could not find anything which solve this problem.

如何实现这一目标?请帮助我知道,因为我阅读了很多 struts2 的书籍,但找不到任何可以解决此问题的内容。

Before i was using PHP framework codeigniterwhich easily solve this type of problem using uri segment features(click here). I am aspecting the same here in Struts2.

在我使用 PHP 框架之前codeigniter,它可以使用uri 段功能轻松解决此类问题 (单击此处)。我在 Struts2 中也是如此。



Given Url String: http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

给定网址字符串http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

Expected Output: sell

预期输出sell

采纳答案by Patrick B.

Did you look for ActionContext#getName()?

你找了ActionContext#getName()吗?

Edit:
Since you were not clear about it, I suppose you want to get the name of the action being executed from inside the action. So, in your action executemethod, you'll have something like this :

编辑
由于您不清楚,我想您想从操作内部获取正在执行的操作的名称。所以,在你的 actionexecute方法中,你会有这样的东西:

String actionName = ActionContext.getContext().getName();

String actionName = ActionContext.getContext().getName();