开发者

Can I have two submit buttons in a jsp to two different controllers?

I am working on a project in which there has to be a functionality to permit the users to update and delete certain rows of a table that will dynamically be displayed t开发者_如何学Pythono them.

The user will click on a radio button to select which row he wants to update or delete and then will click in either the update or submit button.

According to his selection of update or delete, I have to pass the contents of the selected row to 2 a servlet. Now, the servlet for update is different from that of delete. I cannot mention the url pattern in the action attribute of the form as I need the values to be transferred to 2 different servlets according to the users choice.

Is it possible to achieve this?

Please suggest me a few solutions to this problem.


The submit button 's name and value 's attribute will also be POSTED if you click that button to submit the form. In the servlet , you can check if you can get these parameters to know which button is clicked .

For example , suppose you have two buttons , one for update and one for delete

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

If the update button is clicked , it will post the variable update=Update Button If the delete button is clicked , it will post the variable delete=Delete Button

Then in 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
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜