如何在Struts 2中应用全局动态结果路径前缀,因此可以重新封装JSP? [英] How to apply a global dynamic result path prefix in Struts 2 so can reskin JSPs?

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

问题描述

我有一个使用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中的标记,该标记确定是为相关的Action加载新的JSP还是旧的JSP.
  1. store this in the user's session and then
  2. dynamically add /newdesign/ as a global prefix to the 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部分? -我已经考虑过使用struts.convention.result.path = /newdesign,但这不是动态的,如果要向用户显示旧的或新的JSP,则不能更改它.

How do I do part 2. above? - I have looked at using struts.convention.result.path = /newdesign 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中使用的动作名称的前缀指定用于分隔程序包中的动作的名称空间.

The prefix to the action name used in the url specify the namespace used to separate actions in packages.

如果您有多个模块,这些模块具有相同的动作名称和结果,但不同的位置取决于名称空间,则应在具有自己的名称空间的不同程序包中对其进行配置.有一个示例可以让您更好地了解名称空间的概念.

If you have multiple modules that has the same action names and results but different locations that depends on namespace then 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.

您可以使用新设计配置与模块一样多的软件包.如果没有太多,则可以像示例中那样简单地完成.但是,您可以将参数添加到通过

You could configure as many packages as modules you have with new designs. If there's not too many of them then it could be simply done like in example. But instead of switching to the appropriate namespace depending on parameter you could add that parameter to the namespace pattern used via wildcard mappings.

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

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