java 从 Struts 1.2 迁移 -> Struts2 与 Spring-MVC(主要是相对于 Struts1.2 taglib 支持)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3436731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Migration from Struts 1.2 -> Struts2 vs Spring-MVC (primarily vis-a-vis Struts1.2 taglib support)
提问by bogachkov
Primary Question: If my app is CURRENTLY using Struts 1.x - and I am considering migrating to EITHER Spring-MVC or Struts2 for the MVC-framework - is there anything about either one that would make it easier to migrate from Struts1.2?
主要问题:如果我的应用程序当前使用 Struts 1.x - 我正在考虑迁移到 Spring-MVC 或 Struts2 以用于 MVC 框架 - 是否有任何一种可以更轻松地从 Struts1.2 迁移?
To clarify, I am NOT asking whether SpringMVC or Struts2 is better overall (there are a number of existing Q's on SO that address this) - just which one is easier to migrate to from Struts1.2.
澄清一下,我不是在问 SpringMVC 还是 Struts2 总体上是否更好(SO 上有许多现有的 Q 可以解决这个问题)——只是哪个更容易从 Struts1.2 迁移到。
The point that I am most interested in from a migration perspective: possibility of continuing(in the beginning) to use struts1.x's taglib within the JSP pages, while changing to Struts2's (or SpringMVC's) API on the backend.(In other words, can either of these frameworks support Struts1.x's taglib as a plugin)? [Note: this is not intended as a long term solution - but would reduce integration pain, since the JSPs would not need to be immediately rewritten. I assume this question makes sense - if not, please expain why]
从迁移的角度来看,我最感兴趣的一点是:继续(开始时)在 JSP 页面中使用 struts1.x 的 taglib,同时在后端更改为 Struts2(或 SpringMVC)的 API 的可能性。(换句话说,这些框架中的任何一个都可以支持 Struts1.x 的 taglib 作为插件吗)?[注意:这不是一个长期的解决方案 - 但会减少集成的痛苦,因为不需要立即重写 JSP。我认为这个问题是有道理的 - 如果没有,请解释原因]
With that said, I am of course interested in any other migration advantages.
话虽如此,我当然对任何其他迁移优势感兴趣。
Some background:
一些背景:
I am working on an app whose MVC layer is written via Struts 1.2. We are also using Spring IOC - though the app doesn't currently have strong integration between the Struts layer and Spring's DI facilities. (Note: This is something that we plan on correcting when we refactor, but my understanding is that with a bit of planning - this can be done properly/efficiently even when using a Spring IOC+Struts2 combination.)
我正在开发一个应用程序,其 MVC 层是通过 Struts 1.2 编写的。我们也在使用 Spring IOC - 尽管该应用程序目前在 Struts 层和 Spring 的 DI 设施之间没有强大的集成。(注意:这是我们在重构时计划纠正的事情,但我的理解是,通过一些计划 - 即使使用 Spring IOC+Struts2 组合也可以正确/有效地完成。)
As part of improving/refactoring the codebase - we would like to upgrade to a more modern MVC framework (so as to eliminate the need for Action/Form classes, and to use Annotation-based configuration when possible, etc) but keep the overall classic-MVC style (i.e. not currently interested in making the leap to JSF, Tapestry, GWT, Flex, Play, etc. I understand that these are very very different things - lumping them together just to give a general idea..)Also, the desire is to go with something with reasonable traction/momentum - so ruling Stripes out for that reason. This seems to only leave Spring-MVC & Struts2 as contenders (though if there is something else with a similar style and with strong industry traction - we would certainly consider it)
作为改进/重构代码库的一部分 - 我们希望升级到更现代的 MVC 框架(以消除对 Action/Form 类的需要,并在可能的情况下使用基于注解的配置等)但保持整体经典-MVC 风格(即目前对跳到JSF、Tapestry、GWT、Flex、Play 等不感兴趣。我知道这些是非常不同的东西 - 将它们混为一谈只是为了给出一个总体思路......)此外,愿望是采用具有合理牵引力/动力的东西-因此因此将 Stripes 排除在外。这似乎只剩下 Spring-MVC 和 Struts2 作为竞争者(尽管如果有其他具有类似风格和强大行业牵引力的东西 - 我们肯定会考虑它)
It is a given that switching to either of these would require a descent amount of work - but the plan would be to do it on a modular level. For that reason, if either of these supported Struts 1.2's taglib - it would make switching/testing much easier (as we could then code a particular module's "Control" implementation in the new API - and have a 2nd server run the old Struts1.2 implementation using the same jsps. QA testing would then be "apples to apples" in a way. Does this make sense, or would this approach (if even feasible) lead to more headaches than it would resolve?
众所周知,切换到其中任何一个都需要大量的工作——但计划是在模块化水平上进行。出于这个原因,如果这些中的任何一个支持 Struts 1.2 的 taglib - 这将使切换/测试更容易(因为我们可以在新 API 中编写特定模块的“控制”实现 - 并让第二台服务器运行旧的 Struts1 .2 使用相同的 jsps 实现。在某种程度上,QA 测试将是“苹果对苹果”。这是否有意义,或者这种方法(如果可行的话)会导致比它解决的更多的麻烦吗?
Also, as stated above, while my primary question is about running struts1.2's taglib with either Spring-MVC or Struts2 - I am also interested in any other MIGRATION advantages for Struts2-vs-Spring-MVC.
此外,如上所述,虽然我的主要问题是关于使用 Spring-MVC 或 Struts2 运行 struts1.2 的 taglib - 我也对 Struts2-vs-Spring-MVC 的任何其他迁移优势感兴趣。
采纳答案by madth3
I have not seen support for Struts 1 taglib in any of these frameworks.
我在这些框架中都没有看到对 Struts 1 taglib 的支持。
Some minor Struts2 advantages: There are a few official references about migrating applications from Struts1 to Struts2 - http://struts.apache.org/2.2.3.1/docs/migration-strategies.html- http://struts.apache.org/2.2.3.1/docs/migration-tools.html
Struts2 的一些小优势:有一些关于将应用程序从 Struts1 迁移到 Struts2 的官方参考资料 - http://struts.apache.org/2.2.3.1/docs/migration-strategies.html- http://struts.apache.org /2.2.3.1/docs/migration-tools.html
There is even a Struts1 plugin in Struts2 that allows you to run your actions in Struts2 - http://struts.apache.org/2.2.3.1/docs/struts-1-plugin.html
Struts2 中甚至还有一个 Struts1 插件,允许您在 Struts2 中运行您的操作 - http://struts.apache.org/2.2.3.1/docs/struts-1-plugin.html
Unfortunately, this same references say that you have to convert your old JSP's and that is not an easy task.
不幸的是,同样的参考文献说您必须转换旧的 JSP,这不是一件容易的事。
回答by John
If migrate Strut1.2 to Spring MVC, if we include the struts.jar in WEB-INF/lib , we still can use strut1.2 taglib in Spring MVC, that means you still can use bean:define, bean:write... logic:present, logic:equal ... (Struts1.2 taglib) in JSP , only change is struts 1.2 form taglib (html:text,html:error html:form ...) should be changed to spring form taglib (form:path, form:form,form:path,form:error ...) so that we can bind form fields to command class data , referenceData or initialized command data by formBackObject to use spring MVC JSP feature
如果将 Strut1.2 迁移到 Spring MVC,如果我们在 WEB-INF/lib 中包含了 struts.jar,我们仍然可以在 Spring MVC 中使用 strut1.2 taglib,这意味着您仍然可以使用 bean:define, bean:write.. . logic:present, logic:equal ... (Struts1.2 taglib) 在JSP中,唯一的变化是struts 1.2 form taglib (html:text,html:error html:form ...) 应该改为spring form taglib ( form:path, form:form,form:path,form:error ...) 以便我们可以将表单字段绑定到命令类数据、referenceData 或通过 formBackObject 初始化的命令数据以使用 spring MVC JSP 功能
回答by linuxbuild
Try to read and compare the following articles:
尝试阅读并比较以下文章:
- "Spring Your Struts Apps Ahead: The Struts-to-Spring Migration"(Struts 1.x to Spring-MVC)
- "Apache Struts 2 Migration Guide"and "Migrating Struts Apps to Struts 2"(Struts 1.x to Struts2)
- “Spring Your Struts Apps Ahead: The Struts-to-Spring Migration”(Struts 1.x 到 Spring-MVC)
- “Apache Struts 2 迁移指南”和“将 Struts 应用程序迁移到 Struts 2”(Struts 1.x 到 Struts2)
See also: "Migrating from Struts2 to Spring MVC"question at stackoverflow.
另请参阅:stackoverflow 上的“Migrating from Struts2 to Spring MVC”问题。
回答by Dave Newton
Moving to either is essentially the same amount, and type, of work.
转移到任一个基本上是相同数量和类型的工作。
While there isa Struts 1 plugin in S2 that allows use of existing S1 action classes, as noted you still need to rewrite your JSP files, and your app would still suffer from S1's close ties to the servlet framework.
虽然是一个Struts插件1 S2中允许使用现有的S1动作类,如注意你仍然需要重写你的JSP文件和您的应用程序仍然会从S1的密切联系的Servlet框架受到影响。

