aspose file tools*
The moose likes Struts and the fly likes struts 2: how to call action from href link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2: how to call action from href link" Watch "struts 2: how to call action from href link" New topic
Author

struts 2: how to call action from href link

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
normally, we mention the action attribute as a paramater of the form tag. then on click of submit button, the corresponding action class is called. Now, i would like to call action on click of the hyperlink ( i.e. <s:a href tag). how could i achieve it in Struts 2. Please help.>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

You want to call an action when you click a link?

Or you want to submit a form when you click a link?
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
newton, i want to call an action on clicking a link.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And go to that action's page?
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
yes, go to the action page. i forgot to mention one thing that information related to link clicked is also required in the next action page.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617



You'll have to be more specific about that second requirement, I have no idea what it means.
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
David Newton wrote:



thanks newton, after writing above code, execute method of the action class is called. But, i also want to send a value associated with the link clicked to the action class. how could i achieve it.

Let me elaborate the issue:

I have a list of employees with hyperlink on their names. now, i want user to edit an emploee by clicking on its name link. by above code, the execute method of action class is getting called. but i also want to send the emp name to the action class. how could i pass it?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Have you looked at the url tag docs?

From that page:



It's almost always quicker to check the documentation first.
Bilal A. Siddiqui
Ranch Hand

Joined: Sep 14, 2008
Posts: 53

Hi Vikas,

you can send the name or any other value like the way i have show below.




name variable contains the value.

on action page you can get this value by either making getter setter bean of EmpName or by using

request.getParameter("EmpName")


Cheers!!! Bilal
Handsome Android||@bilal_speed||LinkedIn
Gaurav Manral
Greenhorn

Joined: Jun 29, 2012
Posts: 17

vikas sharmaa wrote:
David Newton wrote:

This was very useful David Newton.
But can you tell me, can we do the same like this?


Forgive your enemies, but never forget their names.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2: how to call action from href link
 
Similar Threads
to .do or not to .do?
Clarrifications about global action, scope, types of action
JSP + struts html:select
Struts 2 Display tag
how to include struts action in jsp