我对选择 Struts 1 还是 Struts 2 来完成我的新 Web 应用程序开发任务有些困惑。谁能从架构的角度建议我应该使用哪个框架进行开发?在进行应用程序开发之前,选择struts版本应该注意哪些要点? 任何帮助将不胜感激。
最佳答案
嗨,我更喜欢 struts 2,因为,
Struts 1.x
- 在 struts 1.x 中,前端 Controller 是 ActionServlet
- 在 struts 1.x 中我们有 RequestProcessor 类
- 在 struts 1.x 中,我们有多个标签库,如 html、logic、bean..etc
- 在 struts 1.x 中,配置名称可以是 [任何名称].xml,我们通常将其放在 web-inf 文件夹中
- 在 struts 1.x 中,我们分别有form beans 和Action classes
- 在 struts 1.x 中,Action 类是一个单一的类,因此 Action 类对象不是线程安全的,作为程序员,我们需要通过应用同步使其成为线程安全的
- 在 struts 1.x 中我们只有 jsp 作为 View 技术
Struts 2.X
- 在 2.x 中,前端 Controller 是 FilterDispatcher
- 在 2.x 中我们有 Interceptors 而不是 RequestProcessor
- 在 2.x 中,我们没有多个库,而是包含所有标签的单个库
- 在 2.x 中,配置文件只能是 struts.xml,并且必须位于 classes 文件夹中
- 在2.x form bean中,Action类只是组合给Action类,当然我们也可以单独拿
- 在2.x中会为每个请求创建一个Action类对象,所以默认是线程安全的,所以我们这里不需要关心安全问题
- 在 2.x 中,我们支持多 View 技术,如 velocity、Freemarker、jasper reports、jsp。
关于struts2 - Struts 1 或 Struts 2。哪一个适合 Web 应用程序开发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18773918/