Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Struts Forward Action Example 
 

In this section we will learn about Struts ForwardAction (org.apache.struts.actions.ForwardAction). The ForwardAction is one of the Built-in Actions that is shipped with struts framework.

 

Struts Forward Action Example

                         

In this section we  will learn about Struts ForwardAction (org.apache.struts.actions.ForwardAction). The ForwardAction is one of the Built-in Actions that is shipped with struts framework.

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 you will learn more about Struts Forward Action that will help you in grasping the concept better.

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 .

<action
path="/success"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Success.jsp"

input="/pages/ForwardAction.jsp"
scope="request"
validate="false">
</action>

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">
<HEAD>
<TITLE>Forward Action Example</TITLE>
<BODY>

<H3>Forward Action Example</H3>
<p><html:link page="/success.do">Call the Success page</html:link></p> 
</html:html>

Add the following line in the index.jsp to call the form.

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

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. Your browser will display the following ForwardAction page.

Selecting  Call the Success page  displays the following Success.jsp page

 

                         

» View all related tutorials
Related Tags: c programming apache web com development asp ui framework build application io components make sed get ip hook vi concepts

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi,

The roseindia.net is a great site for learners and beginners.
Thanks to roseindia.

Posted by gopikrishna on Wednesday, 12.3.08 @ 05:16am | #82320

if i have a form in the page....can i use the forwardaction class to forward the the form page.

if i do, it flashes the error "cannot retrieve the form bean definition null"

Posted by bala on Wednesday, 05.14.08 @ 12:42pm | #59776

I tried to use the example above and I am getting a message that attribute input is allowed only when attribute name is specified. Can you explain this error to me.
thanks

Posted by stan on Wednesday, 02.20.08 @ 20:38pm | #49230

description The request sent by the client was syntactically incorrect (Invalid path /success was requested)

i used the following coding:

<action
path="/success"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Success.jsp"
input="/pages/ForwardAction.jsp"
scope="request"
validate="false">
</action>

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

<H3>Forward Action Example</H3>
<p><html:link page="/success.do">Call the Success page</html:link></p>
</html:html>

Posted by mohan on Friday, 08.17.07 @ 08:55am | #23562

Can we use multiple action? If yes then what is the name of class.

Posted by Madhu on Wednesday, 06.27.07 @ 12:33pm | #20269

hi
i got the error:

HTTP Status 400 - Invalid path /success was requested

--------------------------------------------------------------------------------

type Status report

message Invalid path /success was requested

description The request sent by the client was syntactically incorrect (Invalid path /success was requested)

i used the following coding:

<action
path="/success"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Success.jsp"
input="/pages/ForwardAction.jsp"
scope="request"
validate="false">
</action>

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

<H3>Forward Action Example</H3>
<p><html:link page="/success.do">Call the Success page</html:link></p>
</html:html>

please tell me why the error come

Posted by nilesh zare on Wednesday, 05.30.07 @ 11:55am | #17711

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.