This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 - Not forwarding to another action using type= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 - Not forwarding to another action using type="Dispatcher"" Watch "Struts2 - Not forwarding to another action using type="Dispatcher"" New topic
Author

Struts2 - Not forwarding to another action using type="Dispatcher"

udhaya kanagaraj
Ranch Hand

Joined: Mar 31, 2005
Posts: 62
Hi all,

I am worlimg with Strts2. I am new to struts2 as well. Facing a lot of problems in development using struts2. Need your help in dispatching an action from struts.xml. Please help me if anyone have faced similar kind of problem

If I use type="dispatcher" in <result> tag, the action is not dispatched to the specified action. It's not throwing an exception as well. But if I use type="redirectAction", the action is redirected, but my request object is lost. So I don't want to redirect.
I want to farward the action with out losing the request object.

Also if I specify a JSP page in the dispatcher, it's working fine
ie)
Working


Working


Not Working



I am using jdk1.6,struts2.1.6, weblogic10.3. Please help me to solve this problem
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

AFAIK "dispatcher" is just using a regular forward, which means it can only access servlet resources (JSP, servlet, etc.)
udhaya kanagaraj
Ranch Hand

Joined: Mar 31, 2005
Posts: 62
Thanks David.

Could you please suggest me the alternative for using dispatcher

I am struggling with this problem for the past one week.

Please help me to solve this issue.


Thanks and Regards,
Udhaya
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Figure out different program logic.

Depending on your specific needs, which I obviously don't know, you might be able to use dynamic results (see here and here), keep data in the session, possibly use action chaining (NOT recommended), or some other solution.
siddiq syed
Greenhorn

Joined: Aug 14, 2008
Posts: 6
Hi all,

I am struggling with the same problem , Did any got the solution. ?

I have a problem with forwarding the request to an action.
I am using validations for the fields mention on the form , once validation fails as struts defined it will check for result name "Input".
If the result name "Input" is defined with result type "redirect-action" as shown below , this will forward to the mention action with new request.
<result name="input" type="redirect-action">
Is there any way where I can forward to an action , but still can use the old request object, throught will I can display the invalid values that user enter.
I tried all the result type like :
dispatcher --- Dispacther uses the old request object but the location must be a view not an action.
Chain --- chain uses the old request object but it is excuted irrespective of what happen , life even if the validation pass chain is going to exucute.
redirect -- same as redirect-action.
Do anybody got such a problem earlier. ?
Temp solution :
I am setting the values in the session in the getter method of the object. and setting back to the new request removing it from the session.
But i think this is a temp solution , there should be a direct solution where we can speicfy in resut-type like redirect with the old request object.
Please any Inputs are highly appreicated.

Parag Bhole
Greenhorn

Joined: Aug 31, 2012
Posts: 2
Topic looks old but still replying here if someone facing same issue.
I tried defining the new global result type as <result-type name="forwardAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult" /> and used this result type in the action result type where it is required to forward to another action. e.g
<action name="someAction" class="someActionClass">
<result name="success" type="forwardAction">${nextAction}</result>
</action>
Worked for me, but not sure if that is correct way.
Parag Bhole
Greenhorn

Joined: Aug 31, 2012
Posts: 2
Earlier post was wrong, actually org.apache.struts2.dispatcher.ServletActionRedirectResult is already present in struts-default "redirectAction".
struts-default "chain" result type is forwarding the action.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts2 - Not forwarding to another action using type="Dispatcher"