I'm working on an webapp where the user selects an account to work with, then all URLs they click thereafter refer to that account. Currently the active account is stored in the session, but that means it's not included in user bookmarks, it's lost when the user's session times out, and when the user shares links they don't include the relevant account...
Is there any way I can include the accountID
in every URL without adding it manually to all URLs in the (rather large & still growing) webapp?
One approach would be to make it the first part of the path, so all URLs would be something like:
- /123/discussions/view.do
- /123/account/edit.do
and so on, where 123
is the accountID
.
If all paths could be relative, that'd work just fine. But I haven't figured out how to get this kind of approach to play nicely with Struts namespaces.
Normally, all paths generated by the Struts2 taglibs start with /
, and action wildcard matches also doesn't kick in until after the namespace is matched.
If I can somehow get the accountID
in the path after the namespace part, I can hit the right action with action wildcards, I think, but the hard part is still getting the ID into the URLs in the first place.
The best solution may just be making custom versions of <s:a>
, <s:form>
, and <s:url>
, but I'm not sure how easy that is.
IMPORTANT
There are a few answers that address only how to map these URLs to Action
s.
The harder part of this problem is actually how to get the accountID
into all URLs and form paths without manually adding it to each one throughout the application.
Currently it seems to me that the only way will be to make custom versions of Struts JSP tags for URLs and forms. So any pointers on how to do that would be useful.