• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Help-simple question

 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am having trouble in dealing with JSP pages.
I have a JSP page which has a set of submit buttons which were generated by using a for loop. Now I have set it up to go to the next JSP page.But I do want to know the index of the button which was clicked.
Its a simple problem for the ones who has been doing it for a while.
Please help me in this regard,
Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a submit button is clicked, it's name is put in the request. None of the other submit buttons will be in the request except the one that is clicked. So one way of doing this is a simple IF statement:



That is how I have always done it. Not sure how many other ways there are.
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an array of submit buttons.Not like there is one button and to check if that is pressed or not. I want to know the index of the submit in that array which has been pressed.
Thanks
 
Baps Vakkalagadda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you can solve it using client side scripting and hidden form element.

include a hidden form element like: <input type="hidden" name="submittype" value="">.

Set the value of this hidden variable to submit button name using client side scripting before form is submitted. You can retrieve this value at server side in your next JSP page.

I hope it will solve your problem ...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bubly Karri:
I have an array of submit buttons.Not like there is one button and to check if that is pressed or not. I want to know the index of the submit in that array which has been pressed.
Thanks


You could still do it the way I sugested.

Once the page reaches the client, it is no longer an array of buttons. It's just a bunch of submit buttons. What array are you going to check? There isn't an array anymore.

And if they are all in a single form element, only one will ever be sent back to the server with the request. So as you iterate over your loop and spit out each submit button, give them a name accordingly (button1, button2, etc). Then check to see which one was pressed.
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. I could solve the problem
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bubly Karri:
Thanks for the replies. I could solve the problem


Care to share with us how so that others can learn in case they run into a similar issue?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!