【发布时间】:2011-01-07 09:02:27
【问题描述】:
我正在为一个项目创建自己的自定义 MVC Web 框架。这个项目有非常古老的代码库,其中一个 JSP 页面直接向另一个 JSP 提交表单,而路径也是硬编码的。现在这是一个大项目,放置 Struts 或 JSF 将需要相当长的时间。 所以我的建议是构建一个小型的自定义 MVC 框架并将许多现有的页面流转换到其中,并鼓励他们使用这个新的 MVC 框架开发更新的应用程序。
我想和大家一起回顾一下这是否有意义,或者我们应该直接使用标准 MVC 框架。
我的想法
1. Create one front controller servlet which will have URL pattern like /*.sm
2. This servlet reads one config file and creates a map whose key is requestedURI and value is the class name of the command bean.
3. upon intercepting any action request it reads the parameter map (request.getParameterMap()). This servlet refers the already built map, understand whose command bean is to be invoked? Creates an instance of this command bean.
4. pass the parameter map to this command bean and calls execute method.
5. if any exception is found, front controller servlet forwards the request to one global error page
6. if everything is fine, it then forwards the request to the expected URI (by removong .sm and replace it with .jsp)
你认为我在这里遗漏了什么吗?我知道我可以通过在配置文件中为每个请求页面提供错误页面来使它更花哨,但这些也可以在以后完成。
【问题讨论】:
标签: java model-view-controller jsp servlets