问题
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:
- store this in the user's session and then
- dynamically add
/newdesign/
as a global prefix to the tag instruts.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 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:
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 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.
来源:https://stackoverflow.com/questions/16523683/how-to-apply-a-global-dynamic-result-path-prefix-in-struts-2-so-can-reskin-jsps