You could start by adding a method to a base class for your application
that would append a tag according to the browser detected, and then use
this scheme:
> <forward name="ie_success" path="/ie/test.jsp"/>
> <forward name="ns_success" path="/ns/test.jsp"/>
> <forward name="wap_success" path="/wap/test.jsp"/>
by returning something like
return ( findForward( browserTag("success") ) ;
where browserTag prepended the "ie" part.
The idea of being to forward to relative directories also came up here
the other day:
<
http://www.mail-archive.com/struts-dev%40jakarta.apache.org/msg01779.html
>
Hans Bure wrote:
>
> Hi all,
>
> I am a relatively new struts user, so if the question I'm asking has been
> answered before, I appologize ahead of time.
>
> What I'm trying to do, is create a framework integrated with struts that,
> among other things, allows users to set up multiple forwards dependent on
> the broswer type. This could be Netscape, IE, WAP browser, or others.
>
> What I would like to do is something like the following in the
> struts-config.xml file:
>
> ...
> <action name="test">
> ...
> <forward name="success" browser="IE" path="/ie/test.jsp"/>
> <forward name="success" browser="NS" path="/ns/test.jsp"/>
> <forward name="success" browser="WAP" path="/wap/test.jsp"/>
> ...
> </action>
> ...
>
> The reasoning behind this, would be to create an additional attribute that
> could be used by my framework internals that determines the browser and
> calls the correct JSP for the user automatically.
>
> Something like:
>
> ...
> return myMapping.findForward("success");
> ...
>
> Which calls into a wrapper class that I create and determines the browser,
> then calling the appropriate JSP as defined in the config file. This makes
> it very simple for the user, as he only needs to define a series of
> 'success's, and the Action code is simple as defined above.
>
> Now, obviously, adding an additional attribute to the forward above is not
> trivial. So my question, is has anyone seen anything like this, and is
> there a way I haven't thought of to do this within the current struts
> framework?
>
> One thought I've had would be to do the following:
>
> <forward name="ie_success" path="/ie/test.jsp"/>
> <forward name="ns_success" path="/ns/test.jsp"/>
> <forward name="wap_success" path="/wap/test.jsp"/>
>
> This would work and not require many changes to the framework, but I would
> rather not do this, as it would make things very difficult for my users to
> create their own actions.
>
> Another possibility is the following:
>
> <forward name="success" path="test.jsp" />
> <browserforward name="success" browser="ie" path="/ie/test.jsp" />
> <browserforward name="success" browser="ns" path="/ns/test.jsp" />
> <browserforward name="success" broswer="wap" path="/wap/test.jsp" />
>
> In this case, I would need to create another XML entry that kept all of the
> 'success' forwards for each action in its own little HashTable, much like
> the normal forwards, except keyed by a combination of the name and the
> browser attributes.
>
> I honestly don't know how difficult this would be, but it seems like the
> best solution I've come up with so far. One obvious drawback to this one is
> that the struts DTD would need to be altered to include the 'browserforward'
> element. I am not sure of the implications of this.
>
> Any thoughts?
>
> Thanks for your time.
>
> Hans Bure