This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 Action Not forwarding to a result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Action Not forwarding to a result" Watch "Struts2 Action Not forwarding to a result" New topic
Author

Struts2 Action Not forwarding to a result

Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Hi,

I have my action configured in struts-xml, evidently my action completes succesfully because when I refresh the view I can see the result I expect. However the problem is that my action remains on a blank page after completing. What could be the problem?

Im on struts 2.2.1. Here is my action execute and mapping


public String execute(){
try{
member = new MemberService().saveMember(member);
return SUCCESS;
}catch(Exception e){
return ERROR;
}
}



struts.xml


<action name="addMember" class="action.AddMember"
method="execute">
<result name="success" type="dispatcher">/viewmembers.jsp</result>
<result name="error">/error.jsp</result>
<result name="input">/addMember.jsp</result>
</action>


What am i doing wrong? It should at least forward to the error page if there was an error. And like I said when i manually open the viewmembers.jsp I can see that my hibernate code worked perfectly. Help.



Best,
Mlati
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
You may be getting some kind of failure in your jsp. Did you check the log file for your app server? Maybe putting some println statements early in the JSP would help identify if the JSP is being run.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Tom Rispoli wrote:You may be getting some kind of failure in your jsp. Did you check the log file for your app server? Maybe putting some println statements early in the JSP would help identify if the JSP is being run.


I'm using tomcat 7, the logs don't show anything unusual. I don't know if I'm missing a required jar but I thought forwards must be part of struts2-core.jar ..I have noticed that non of the forwards actually work anymore. For example if I deliberately make the database unavailable to simulate a hibernate exception I still get stuck in a blank action page instead of getting forwarded to the error page.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Do you have the xwork jar file in your class path? I think xwork might handle the forwarding stuff.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Tom Rispoli wrote:Do you have the xwork jar file in your class path? I think xwork might handle the forwarding stuff.


Yes I have xwork-core2.2.1.1.jar in my WEB-INF/lib folder
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Tom Rispoli wrote:You may be getting some kind of failure in your jsp. Did you check the log file for your app server? Maybe putting some println statements early in the JSP would help identify if the JSP is being run.


I added some prinln statements and I can see their output on tomcat console...but I still aint getting forwarded to this page. I don't think JSP is the problem because if i request the page by itself it gets rendered completely with the hibernate results showing that the action was successful.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Samson Mlati wrote:
Tom Rispoli wrote:You may be getting some kind of failure in your jsp. Did you check the log file for your app server? Maybe putting some println statements early in the JSP would help identify if the JSP is being run.


I added some prinln statements and I can see their output on tomcat console...but I still aint getting forwarded to this page. I don't think JSP is the problem because if i request the page by itself it gets rendered completely with the hibernate results showing that the action was successful.



After almost giving up I figured out my mistake. I was forwarding to a JSP page that is a result to another action, I fixed it by configuring my action result to type redirectAction that forwards to the appropriate action. Works like a charm!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 Action Not forwarding to a result
 
Similar Threads
Result attribute in Struts 2
params in the url - struts 2
Struts2-json plugin not serializing action class to json
Struts 2 - Yet another combobox prepopulation using prepare method question
Struts 2 forms with different actions