Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

struts2

I am having a active page with its url like 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.

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.

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.


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

Expected Output: sell

like image 840
Dan Avatar asked Oct 20 '25 13:10

Dan


1 Answers

Did you look for 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 :

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

like image 88
Patrick B. Avatar answered Oct 23 '25 04:10

Patrick B.