简体   繁体   English

Java / Struts2:如何从当前URL获取动作名称

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

I am having a active page with its url like http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22 我有一个活动页面,其URL如http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

Now i want get the action name(4th name after the sign / ) ie 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 codeigniter which easily solve this type of problem using uri segment features(click here) . 在我使用PHP框架codeigniter之前,使用uri段功能轻松解决这类问题(点击这里) I am aspecting the same here in Struts2. 我在Struts2中面向同样的方面。


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

Expected Output : sell 预期产出sell

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 execute method, you'll have something like this : 所以,在你的动作execute方法中,你会有这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM