Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 10-08-2009
Join Date: Jul 2009
Posts: 1,113
Struts Forward Action with example


I have a problem that when I use struts it creates a new request & my attributes of the original gets lost. Do anyone have any idea to get ride of this problem?

Can someone explain with an example of Struts Forward Action?

Thanks in advance.
Reply With Quote
Old 10-08-2009
Join Date: May 2008
Posts: 44
Re: Struts Forward Action with example

Struts Forward Action Example

The org.apache.struts.actions.ForwardAction class enables a user to forward request to the specified URL. ForwardAction is an utility classs that is used in cases where a user simply needs to forward the control to an another JSP page. Linking directly a JSP to an another, violates the MVC principles. So we achieve this through action-mapping. Note that we do not create any action class. With ForwardAction , simply create an action mapping in the Strut Configuration and specify the location where the action will forward the request..

Here in this example

No need to develop an Action Class

Developing the Action Mapping in the struts-config.xml

Create seperate action-mapping , for each page you want to link.. Note that the "type" attribute always take "org.apache.struts.actions.ForwardAction" value. Here "parameter" attribute specifies the URL to which the request is forwarded .

Developing a jsp page

Code of the jsp (ForwardAction.jsp) to forward request to a different jsp page :

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> 
<html:html locale="true">
<TITLE>Forward Action Example</TITLE>

<H3>Forward Action Example</H3>
<p><html:link page="/success.do">Call the Success page</html:link></p> 
Add the following line in the index.jsp to call the form.

<html:link page="/pages/ForwardAction.jsp">Struts Forward Action</html:link>
Example shows you how to use forward class to forward request to another JSP page.

Building and Testing the Example

To build and deploy the application go to Struts\Strutstutorial directory and type ant on the command prompt. This will deploy the application. Open the browser and navigate to the ForwardAction.jsp page.

I hope this example helps you out.
Reply With Quote
Old 10-08-2009
Join Date: Jul 2009
Posts: 1,113
Re: Struts Forward Action with example

Hey thanks for the example & the tutorial ill let you know if I get any problem regarding this struts forward action.

Thanks for the quick reply.
Reply With Quote

  TechArena Community > Software > Software Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Struts Forward Action with example"
Thread Thread Starter Forum Replies Last Post
Struts 1 VS Struts 2 PsychoVillan Software Development 6 29-03-2011 12:23 AM
Beginning with the Struts 2 Ronchi Software Development 4 19-03-2011 06:32 AM
JSF versus Struts Daksha Software Development 3 21-07-2010 06:20 AM
Setting a cookie via Struts Cadallic Software Development 3 25-10-2008 03:08 PM
Calling Struts using Javascript Novino Software Development 2 25-10-2008 02:42 PM

All times are GMT +5.5. The time now is 11:10 PM.