File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 8997
    
    9

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.


[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.