• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2: how to distinguish multiple submit button call in the action class

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have implemented a simple login application in Struts 2. In the login page, i added 2 buttons. first button is for the new user registration process and second button to login process for existing users. Now, on click of either button calls the execute method of the same action class. how could i distinguish them in the execute call? for your reference, login.jsp is attached below:



please tell me the best way of implementing the above logic in struts 2.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it is not possible to have two submit but for a single form.. why can't you make "sign-up" as a hyperlink, since sign-up just have to open the register page and you really don't have any information to send to the server..
 
vikas sharmaa
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks gopi chand, it seems to be a better approach. but, from the learning struts approach, i want to implement 2 buttons on the same form. and then on click of those buttons, separate process executed. i am able to put 2 submit buttons on the same form with different name as mentioned in the login.jsp file of my first post. but am not able to distinguish them in the execute method call.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value of the submit button, like all the other HTML input tags, gets submitted with the form in a variable which has the same name as the "name" parameter (in your code, "signin" and "newuser"). You can add those two variables to your Action and check which one gets set.
Another solution would be to use JavaScript to change the target of the form depending on which button is pressed. See here for an example.
 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic