让我们快速看看什么是MVC?
MVC(Mode-view-controller)
顾名思义就是软件架构模式,它鼓励应用到have its Model Classes (i.e domain models/DTOs) views (i.e can be JSP, JSON etc) and controller (i.e Servlet) to be as modularized as possible so that it encourages re-usability, loose-coupling between the different layers and Seperation of Concerns
。
所以这个背后的关键想法是encourage Seperation of Concerns
。 Say i want to change the view from JSP to freemarker view , if MVC is tighly followed , i should be able to accomplish the change with minimum to no impact to Controller layer (i.e Servlets)
那么你看到,只有在我的webapp中有清晰的图层分离才能实现。 If i had just scattered all the functions without regard to MVC like having views generated from the Servlet, or making service level calls like accessing the DB directly from the Controller etc is bad because any change in the view or the Database layer will cause massive changes at the Servlet .
所以要回答你的问题your servlet should not directly produce the HTML output
。 Store all the objects
将要生成视图in Request Attribute
和access it in JSP
并重新编译Sevlet并不意味着你不遵循MVC,只是按照MVC的变化是最小的,在一个地方进行分组。
现在下降JSON的概念,使之简单明了 通过这个教程,其中相当解释你如何实现一个整洁的MVC
Jsp MVC tutorial.
一旦你掌握,你可以随时添加更多复杂之类的东西JSON,AJAX异步请求等
thnks所有帮助提供:) – 2013-02-28 17:16:38
@ user2106092欢迎 – Sudhakar 2013-03-01 08:07:18