File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes difference between type and forward??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "difference between type and forward???" Watch "difference between type and forward???" New topic

difference between type and forward???

subho saha
Ranch Hand

Joined: Jun 15, 2005
Posts: 57
I am new to struts. Can somebody explain to me the difference between forward and type attributes of action element in struts-config.xml.
In books it is written type is used when we want to use an action and forward when we donot want an action to happen.But i want to know when should i use type and when forward in building a project..They seem to do the same job.What is the actual difference.

I am confused.
[ December 18, 2005: Message edited by: subho saha ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
My view of this is that in almost every case, you will use Type instead of Forward. Using Type causes struts to call your action before forwarding to a JSP. In a real application, there is almost always some processing you want to do before displaying a JSP.

About the only thing I use the forward option for is when I have a simple jsp that requires no setup to display, but I don't really want the user to see xyz.jsp as the url on the browser. So, I set up an xyz action that forwards to xyz.jsp. That way the user sees as the url on the browser.
[ December 18, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
pax smith
Ranch Hand

Joined: Dec 13, 2005
Posts: 45
Forward simply transfer the control to another JSP without having action class between them

Type refres to a action class that will be executed before JSP executes. It performs all the work perior to JSP.
I agree. Here's the link:
subject: difference between type and forward???
It's not a secret anymore!