0

Incorrect success forward path is set for all the users:

I have this in struts config:

<action path="/abc" type="com.actionclass">
  <forward name="success" path="/jsp/user/abc.jsp" />
</action>

In my action class, I changed the "success" forward path to "www.google.com", if the user satisfies some criteria and then he is getting redirected there.

Although, once any user satisfies this criteria, all the subsequent users are getting redirected to "www.google.com", whether they satisfy the criteria or not, because we are using the same mapping name as "success".

May i know the reason for that? Why the path from struts config is not getting picked as "abc.jsp" for the other users?

P.S : If i restart the server, then again it works fine till any user satisfies the criteria and "www.google.com" is set.

Edit: My action is a logout action, and it has the feature the logout users to different urls of their organization, basically once they logout from our app, this class will redirect them to their organization's page, so its a dynamic url coming from database. Although i know its not the correct way but i want to understand the concept here more than the problem's solution.

  • What do you mean you change the forward path to something else in the action class? Why would you do that? How are you doing that? You should define a new forward in your configuration. – Dave Newton Aug 29 '18 at 16:22
  • My action is a logout action, and it has the feature the logout users to different urls of their organization, basically once they logout from our app, this class will redirect them to their organization's page, so its a dynamic url coming from database. Although i know its not the correct way but i want to understand the concept here more than the problem's solution. – Harish Budhwani Aug 30 '18 at 14:10

1 Answers1

0

Changing the "success" forward path programatically changes the struts mapping for the entire app. You should add a new <forward> tag for redirecting users to another mapping.

For example, I think your config would be something like...

<action path="/abc" type="com.actionclass">
   <forward name="success" path="/jsp/user/abc.jsp"/>
   <forward name="redirect" path="www.google.com"/>
</action>

Then you would give a return result of "redirect" in your actionclass to redirect users to google.

Michael
  • 368
  • 2
  • 8
  • Hi Michael, my action is a logout action, and it has the feature the logout users to different urls of their organization, basically once they logout from our app, this class will redirect them to their organization's page, so its a dynamic url coming from database. Although i know its not the correct way but i want to understand the concept here more than the problem's solution. Till the server is restarted, why the xml value is not getting picked once it is set programatically? – Harish Budhwani Aug 30 '18 at 14:12
  • The config gets read once at startup. From that point on, the mapping from "success" to "/jsp/user/abc.jsp" is stored in memory, and that is what your app will reference when it redirects users (not the config!). Once a user triggers your code that remaps the "success" action, the in-memory path value is overwritten with "www.google.com". The framework does not read your struts config for every redirect - it uses what is in memory. – Michael Aug 30 '18 at 15:04
  • Thanks michael for the explanation. This is exactly what i wanted to know. – Harish Budhwani Aug 31 '18 at 09:21
  • No problem! Happy coding – Michael Aug 31 '18 at 17:09