从 Struts 到 Tapestry 5 的零碎转换
我有一个 Struts (1.3.8) 应用程序,我想将其转换为 Tapestry 5。可能没有时间一次性完成整个转换。 我想在 Tapestry 中提供新功能,并在时间允许的情况下转换现有的 Struts / JSP。 有人尝试过这样的事情吗? Struts 和 Tapestry 可以共存吗?
I have a Struts (1.3.8) application that I'd like to convert to Tapestry 5. There will probably not be time to do the whole conversion in one fell swoop. I'd like to deliver new functionality in Tapestry and convert existing Struts / JSPs as time permits. Has anyone attempted something like this? Can Struts and Tapestry co-exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您按照大多数人的方式使用 Struts,那么您可能拥有所有以 /action 开头或以 .do 结尾的 Struts url。 正如 Shiny 和 New 先生所指出的,这意味着您可以使用 Tapestry 过滤器和 Struts 过滤器或 servlet 来过滤不同的 URL。 我已经使用过这两种方法,并且强烈建议您尝试让 Tapestry 不必处理 Struts URL。 使用 Struts,您几乎可以对 URL 进行手动编码,因此链接到 Tapestry 页面应该不成问题,但如果您希望 Tapestry 链接回 Struts URL,则以标准方式使用它可能会遇到麻烦。 理想情况下,您可以拆分应用程序的一部分(例如内部管理功能)并让它们完全独立。
If you did Struts the way most people do it, you probably have all of your Struts urls starting with /action or ending with .do. As Mr. Shiny and New pointed out, that means you can filter different URLs with the Tapestry filter and the Struts filter or servlet. I've used both and I would strongly recommend that you try to keep Tapestry from having to deal with Struts URLs. With Struts you can pretty much hand-code the URL so it shouldn't be a problem to link to Tapestry pages, but if you want Tapestry to link back to Struts URLs you may have trouble using it the standard way. Ideally, you can split off a portion of your app (like internal admin functions) and have them be completely independent.
如果没有使用 Tapestry,我会说任何两个框架都应该能够共存,因为在
web.xml
中您定义了 url 如何映射到 servlet/filters。 例如,在 Wicket 中,有一个过滤器用于检查实现请求处理程序的 Wicket 类。 如果没有匹配的内容,则请求将沿链向上传递。 这将允许您继续使用 Struts 来执行某些操作。如果您有一些想要保留的 URL,您只需更改 Struts 操作以转发到新的内部 URL; 最终,您所有的 struts 操作本质上都是 url 重写操作,您可以直接删除 struts 并将其替换为 url 重写过滤器。
如果您的新网址不会与旧网址冲突,那么没什么困难的。 只需设置新框架及其请求处理程序。 当遇到 Struts 操作 (
/doSomething.do
) 时,StrutsActionServlet
会将请求分派给该操作。 在struts-config.xml
中,您可以转发到正确的位置,可以是 JSP、tile 或 Tapestry URL。 我想在 Tapestry 中,有一种方法可以在处理完请求后转发到任意 url; 如果需要,只需转发到 Struts 操作即可。我可以预见的一个棘手问题是 Struts 和 Tapestry 对第三方库的要求是否存在冲突。 如果这不起作用,您可能很难进行任何简单的迁移。
Without ever using Tapestry, I'd say that any two frameworks should be able to co-exist because in the
web.xml
you define how the urls map to servlets/filters. For example, in Wicket there is a filter which checks for Wicket classes that implement the request handler. If nothing matches, the request is passed up the chain. This would allow you to continue to use Struts for certain actions.If you have some URLs that you want to preserve, you can just change the Struts action to forward to the new internal URL; eventually all your struts actions will be, essentially, url-rewriting actions, and you can just rip out struts and replace it with a url re-writing filter.
If none of your new URLs will conflict with your old urls, then there is nothing difficult to do. Just set up the new framework and its request handlers. When a struts action is encountered (
/doSomething.do
) the StrutsActionServlet
will dispatch the request to the action. In thestruts-config.xml
you can forward to the right place, either a JSP or a tile or a Tapestry URL. I imagine there is a way, in Tapestry, to forward to an arbitrary url after you're done processing a request; just forward to a Struts action if you need to.The one sticky problem I can foresee is if Struts and Tapestry have conflicting requirements for third-party libs. If that doesn't work you might be seriously out of luck for any kind of easy migration.
我这样做过一次。 我必须在两个框架的会话之间建立桥梁,因为它们为此使用自己的常量/前缀。 我们逐渐从旧版应用程序切换到 T5 应用程序。 我们只是使用 web.xml 将 struts 请求指向 struts,T5 请求将被 T5 过滤器拾取。 我认为您甚至可以配置 T5 过滤器来忽略某些 url。
我们还使用 tuckey URLRewrite 过滤器来控制单个请求是否通过,这样一个页面可能有一天是 struts,下一天是 T5,并且 url 将保持不变(如果您的 struts 应用程序处于活动状态并且人们可能已将其添加为书签,则这非常有用)
我将通读代码(我将其存档在某个地方),如果发现任何问题,我会发回更多内容。
祝你好运。
I did this once. I had to right a bridge between the sessions for the two frameworks since they use there own constants/prefixes for this. We did a gradual switch over from a legacy app to a T5 app. We just used the web.xml to point struts requests at struts and T5 requests would be picked up by the T5 filter. I think you can even configure the T5 filter to ignore certain urls.
We also used the tuckey URLRewrite filter to control were individual requests went, this way a page could be struts one day and T5 the next and the url would remain constant (this is useful if your struts app is live and people may have bookmarked it)
I'll read through the code (I have it archived somewhere) and post back more if I spot any gotchas.
Good luck.