Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionForward

 
pendse anagha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
I have little experience in struts technology - and I have joined a company where they are extensively using struts .

In many catch Blocks I see the code :

I dont seem to understand why we should be doing this ?

Can I not use :


Thanks to all in advance ,
anagha
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What this code is saying is "go back to the jsp that called this action". you need "new", because you are instantiating an object using it's constructor.

Here's a link to the struts JavaDoc which answers most of these questions:

http://struts.apache.org/api/overview-summary.html
 
pendse anagha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Merrill,
Thanks for your reply .
I did check the site that you have so kindly pointed me to .

Couple of more questions come to mind :

Is the creation of a new ActionForward related to maintaining the request ?
ie when I create a new ActionForward - will the struts framework actually do a
RequestDespatcher.forward ? ( thereby maintaining my httpRequest )
and - when I just simply do a mapping.findForward does that mean - that it actually does a response.sendRedirect ( new request )

Thanks for your answers - just wanted to confirm my understanding

-anagha
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Struts architecture, when any action is called (e.g. MyAction.do) it's the Struts ActionServlet that is actually being called. This servlet then reads the struts-config.xml file and calls the execute() method on the appropriate Action class. When the execute() method you write terminates, it must return an instance of ActionForward to the Struts ActionServlet.

When ActionServlet receives this object, it then performs a RequestDispatcher.forward() to the appropriate jsp defined by the ActionFoward. The mapping.findForward() method does nothing more than instantiate an ActionForward class from the name given in the struts-config.xml file. It's the Struts ActionServlet that does the forwarding using the information you pass back to it in the form of an ActionForward instance.

I hope this helps. Good luck.

[ March 09, 2005: Message edited by: Merrill Higginson ]
[ March 09, 2005: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic