Skip to content
Advertisement

How can I get the id of the table element by clicking on the button with struts2 action

I have a product table whose data is taken from mysql. The button is associated with an action that redirects to a jsp that shows that the product has been purchased. I need this action to create a table where it inserts the id of the customer and the product. My problem is being able to retrieve the id for that product.

my action

JavaScript

my jsp

JavaScript

Advertisement

Answer

You need to send the id of the selected item to the action, otherwise it won’T know what was selected. You could do this in at least 2 ways:

  1. Submit a form instead of using a link and put the id into a hidden form field

Something like this (I didn’t use Struts2 in a while so there may be errors):

JavaScript
  1. append the id as a query parameter to the action url, e.g. via the <s:url> tag

Example (same disclaimer as above):

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement