Forward Action Example in struts

Here I am explaining how to do Forward Action in struts .

struts-config.xml

<struts-config>

<action-mappings>
<action path="/forwardtest"
type="org.apache.struts.actions.ForwardAction"
parameter="/ForwardSuccess.jsp"
input="/ForwardTest.jsp">
</action>
</action-mappings>
</struts-config>

web.xml

<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<welcome-file-list>
<welcome-file>ForwardTest.jsp</welcome-file>
</welcome-file-list>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
</web-app>

ForwardTest.jsp


<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:html>
<BODY><bR><br><center>
<H2><u>Forward Action</H2></u>
<html:link page="/forwardtest.do">Click to Forward Success Page</html:link>
</html:html>

ForwardSuccess.jsp

<bR><br><center>
<H2>You Successfully Forwarded</H2>

No comments: