如何在 Struts 2 中应用全局动态结果路径前缀? [英] How to apply a global dynamic result path prefix in Struts 2?

查看:57
本文介绍了如何在 Struts 2 中应用全局动态结果路径前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Struts2 作为 MVC 框架的网站.我需要重新设计 JSP.我需要让旧的 JSP 与新的 JSP 一起访问.所以我添加了一个 /newdesign/ 根文件夹,并将所有现有的 JSP 文件夹复制到其中.

I have a website using Struts2 as the MVC framework. I need to re-skin the JSPs. I need to have the old JSPs accessible alongside the new JSPs. So I have added a root folder of /newdesign/ and copied all of the existing JSP folders into it.

因此,如果我使用名称/值对 ?newdesign=true 登录(例如)我是初始请求,那么我可以:

So if I login with the name/value pair ?newdesign=true (for example) I'm the initial request then I can:

  1. 将其存储在用户的会话中,然后
  2. 动态地将 /newdesign/ 作为全局前缀添加到 struts.xml 中的 <result> 标记,以确定新的或为相关的 Action 加载旧的 JSP.
  1. Store this in the user's session and then
  2. Dynamically add /newdesign/ as a global prefix to the <result> tag in struts.xml that determines if the new or old JSP is loaded for the related Action.

通过这种方式,开发人员可以检查是否所有旧页面都已重新设计为新页面.

This way the developer can check if all the old page has been re-skinned into a new page.

我怎样才能完成上面的第 2 部分?

How can I do part 2 above?

我看过使用

struts.convention.result.path =/newdesign

但这不是动态的,如果要向用户显示旧的或新的 JSP,我无法更改它.

but this is not dynamic and I cannot change it if the user is to be shown the old or new JSPs.

推荐答案

如果您知道第 1 部分,那么假设您可以将参数设置为应该重定向到包含命名空间的其他包的适当操作的操作对应于您的参数 newdesign.

If you know the part 1 then assume you could set the parameter to the action that should redirect to the appropriate action of the other packages that contain the namespace that is corresponding to your parameter newdesign.

URL 中使用操作名称的前缀来指定命名空间以分隔包中的操作.因此,newdesign 将通过不同的命名空间转到单独的模块.

The prefix to the action name is used in the URL to specify the namespace to separate actions in packages. So, the newdesign is going to the separate module by different namespace.

现在您有两个模块,它们具有相同的操作名称和结果,但位置不同,这取决于命名空间.您应该在具有自己命名空间的不同包中配置它们.有一个 example 可以让你更好地理解命名空间的概念.

Now you have two modules that has the same action names and results but different locations that depends on namespace. You should configure them in different packages that have their own namespaces. There's an example that would let you better understand the namespaces concept.

为了简化你的包配置,你可以通过 通配符映射.

To simplify your packages configuration you can use a parameter in namespace via wildcard mappings.

这篇关于如何在 Struts 2 中应用全局动态结果路径前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆