struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <>
Subject Re: Parameterizing the struts-config file
Date Mon, 05 Feb 2007 20:48:34 GMT
Thom Burnett wrote:
> Can I use a parameter instead of a hard coded value in the mappings of a
> struts-config.xml?
> If so, how?
> What I mean is:
> I have a config file that looks like so:
>    <action path="/myAction" type="com.softrek.conference.MyAction"
>            name=" myForm" scope="request"
>            validate="false" >
>        <forward name="winMoney" redirect="true" path="winner.jsp" />
>        <forward name="loser" path="thankYou.jsp" />
>        ....
>    </action>
> This requires an Action that has exactly
> 'winMoney' and 'loser' as the strings in the mapping.findForward().
> Can I use some sort of ForwardNames.WIN_MONEY instead? Or any other
> parameter that will keep the strings identical. Ideally with only one place
> to modify the string if it changes.
> Is this possible? How?

I don't believe there's any way to refer to a static Java constant from 
within struts-config.xml, unfortunately. However, there are a couple of 
projects which aim to replace XML configuration with annotations for 
Struts 1, which might at least allow you to collect everything into one 
place (the action class).

Another popular approach is to use a small set of 'well known' result 
names ('SUCCESS', 'ERROR', 'FAILURE', etc) which you can then reference 
as constants in your action classes. You still have to make sure that 
your action returns and your config match up, but with a limited set of 
possible values it'll be easier to spot if you have a mis-config.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message