Can I create two submit buttons in jsp for two different controllers?

I am working on a project that should have a function that allows users to update and delete certain rows of a table that will be dynamically displayed for them.

The user presses the switch to select which row he wants to update or delete, and then click either the update button or send.

According to his choice of updating or deleting, I have to pass the contents of the selected line to 2 servlet. Now the servlet for updating is different from the servlet delete. I cannot mention the url pattern in the action attribute of the form, since I need values ​​that need to be passed to two different servlets according to the users choice.

Can this be achieved?

Please offer me some solutions to this problem.

+6
source share
1 answer

The attribute of the name and value of the submit button will also be SENT if you click this button to submit the form. In the servlet, you can check if you can get these parameters to find out which button is pressed.

For example, suppose you have two buttons: one for updating and one for deleting

<input type="submit" name="update" value="Update Button"> <input type="submit" name="delete" value="Delete Button"> 

If you click the update button, it will display the update=Update Button variable update=Update Button If you click the delete button, it will display the delete=Delete Button variable delete=Delete Button

Then to the servlet:

  if (request.getParameter("update") != null) { //update button is clicked //Do the update action or forward the request to the servlet to do update action } else if (request.getParameter("delete") != null) { //delete button is clicked //Do the delete action or forward the request to the servlet to do delete action } 
+18
source

Source: https://habr.com/ru/post/892426/


All Articles