多种形式,一个 servlet - 设计视角
我想启动一个关于处理“多表单,一个 Servlet”场景的线程并讨论其优点和缺点。有多个用例可以部署此模型,一个主要示例是:
AccountDetails.jsp :包含多个表单 UpdateAccountDetalsServlet :根据提交的表单,调用 DAO 方法来更新数据库。
现在,显而易见的解决方案是将隐藏参数传递给 servlet 并确定提交了哪个表单,但这感觉不对。为什么?
我想得到一些反馈。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,那很好。您甚至可以使用枚举:
在新的 Restful 模型之前的 Spring MVC 中,您可以拥有一个多操作控制器。在那里,您必须在 URL 中传递一个参数,例如
method=save
,并且 spring 会在您的对象上调用save()
方法。您也可以实现这一点,但它包括反射。Yes, that is fine. You can even use enums:
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 thesave()
method on your object. This is something you can also implement, but it includes reflection.