How to apply a global dynamic result path prefix in Struts 2?

771 Views Asked by At

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.

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

  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.

How can 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

There are 1 best solutions below

3
On

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.

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.

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.