Servlet handling multiple post requests

前端 未结 2 465
轻奢々
轻奢々 2020-12-31 13:41

I have one Servlet name EditEvent and one JSP which contains two forms. One for adding new event, The other one is for removing an event.

Is it considered as good p

2条回答
  •  -上瘾入骨i
    2020-12-31 14:12

    It's all your choice. It depends all on the current and future functional requirements. A simple alternative is to just introduce one or two if blocks in the servlet wherein you check which button is been pressed:

    if (request.getParameter("add") != null) {
        // Perform add.
    }
    else if (request.getParameter("remove") != null) {
        // Perform remove.
    }
    

    assuming that the buttons look like this:

    
    
    

    A complex alternative is to step over to a normal MVC framework where you just have to specify specific action methods. For example, JSF:

    
    
    

提交回复
热议问题