Java/Struts2:如何从当前 url 获取操作名称 [英] Java/Struts2: How to get action name from current url
问题描述
我有一个活动页面,其 url 像 http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22
I am having a active page with its url like http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22
现在我想获取操作名称(符号 /
后的第四个名称),即 setuppageforwared.
Now i want get the action name(4th name after the sign /
) i.e setuppageforwared.
如何实现?请帮助我知道,因为我阅读了很多 struts2 的书籍,但找不到任何解决此问题的方法.
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.
在我使用 PHP 框架 codeigniter
之前,它使用 uri 段特征(单击此处).我在 Struts2 中也是如此.
Before i was using PHP framework codeigniter
which easily solve this type of problem using uri segment features(click here) . I am aspecting the same here in Struts2.
给定 URL 字符串:http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22
预期产出:sell
推荐答案
您是否在寻找 ActionContext#getName()
?
编辑:
由于您对此不清楚,我想您想从操作内部获取正在执行的操作的名称.因此,在您的操作 execute
方法中,您将拥有如下内容:
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 execute
method, you'll have something like this :
String actionName = ActionContext.getContext().getName();
String actionName = ActionContext.getContext().getName();
这篇关于Java/Struts2:如何从当前 url 获取操作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!