Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

By passing forward in action tag.

 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had declared 2 forwards in the same name. 1 in <action> tag and other in <global-forwards>. But at a certain context can I skip the forward in the <action> tag so that it forwards the page defined in <global-forwards>
Is there any way for that?


<global-forwards>
<forward name="searching" path="searching_common.jsp"/>
</global-forwards>


<action path="/myURL" scope="session" type="myAction">
<forward name="searching" path="/searching.jsp"/>
</action>
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When you have the forwards first struts will search in the <action> and if it doesnt find it there then it will look for global forwards.
In case you want to have the global forward, then you have to change the name of the forward path in your action, or omit it altogether.
<global-forwards>
<forward name="searching" path="searching_common.jsp"/>
</global-forwards>
<action path="/myURL" scope="session" type="myAction">
<forward name="searching_new" path="/searching.jsp"/>
</action>[/
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is Ok, I know.
But I want to know is there any way to skip the forward in <action>
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its simple. Dont use the forward in the action. It will pick from the global-forwards.
<global-forwards>
<forward name="searching" path="searching_common.jsp"/>
</global-forwards>

<action path="/myURL" scope="session" type="myAction">
</action>
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That I know.
I asked that if the same forward is defined in <action> and <global-forward> and is there any way to by pass the forward in <action>

For an interview, the interviewer asked this. For that only I asked this.
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not possible. If you define forwards of the same name at both action level and global level, the one at the global level is inaccessible, since Struts will always pick the one at the action level.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic