aspose file tools*
The moose likes Struts and the fly likes Can we call two different methods based on the same action in Struts2. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Can we call two different methods based on the same action in Struts2. " Watch "Can we call two different methods based on the same action in Struts2. " New topic
Author

Can we call two different methods based on the same action in Struts2.

Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
Can we call two different methods based on the same action in Struts2.

The methods will be called when two different buttons are clicked , for example login button and register button are on the same JSP page.

When we click on login button doLogin() method should be called and when we click on register button doRegister() method should be called.


SCJP 1.5
www.licexpadvice.com
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8713
    
    6

The action tag in struts.xml has a "method" parameter that allows you to specify a method name. The method takes no arguments and must return a String.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
senthil kumar m
Greenhorn

Joined: Nov 28, 2010
Posts: 16
Hrishikesh Maluskar wrote:Can we call two different methods based on the same action in Struts2.

The methods will be called when two different buttons are clicked , for example login button and register button are on the same JSP page.

When we click on login button doLogin() method should be called and when we click on register button doRegister() method should be called.



then..you can use DispatchAction . Extend the DispatchAction in your action class.

And also configure accordingly in struts-config.xml, have parameter="method" as Joe Said..

Read about struts DispatchAction.that will be helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we call two different methods based on the same action in Struts2.
 
Similar Threads
Struts2 ajax theme - One form, two buttons.. two actions?
Handling error messages (Struts2 jquery )
Struts2 and EJB 3 integration
struts2 action
Struts2 Validation