Multiple forms, one servlet - Design perspective
I would like to start a thread on handling the "multipe Form, one Servlet" scenario and discuss pros and cons. There are multiple use cases where this model could be deployed with a prime example being:
AccountDetails.jsp : contains multiple forms UpdateAccountDetalsServlet : depending on which form was submitted, calls a DAO method to update the database.
Now the obvious solution here would be to pass a hidden parameter to the servlet and determine which form was submitted, but this doesn't feel right. Why?
I'd like to get some开发者_运维百科 feedback.
Thanks.
Yes, that is fine. You can even use enums:
OperationType opType = OperationType.valueOf(request.getParameter("opType"));
switch(opType) {
case SAVE..
case DELETE..
}
In Spring MVC prior to the new restful model you could have a multi-action controller. There you had to pass a parameter in the URL, like method=save
, and spring invoked the save()
method on your object. This is something you can also implement, but it includes reflection.
精彩评论