Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struts Dispatch Action Tutorial with example
12-12-2011, 08:56 PM (This post was last modified: 12-18-2011 09:43 PM by rajasri.)
Post: #1
Tongue Struts Dispatch Action Tutorial with example
Today we are going to learn

Struts Dispatch Action Tutorial with example

The two package which needed to be imported are as follows
import org.apache.struts.action.DispatchAction;
import org.apache.struts.action.ActionForm;

The Main features of Dispatch Action are

*One of the Built in Functions in Struts Framework
*The class doesnot provide implement action for the execute() method,Because dispatch action class iteself
implements the method.
*It eliminates the need of creating multiple independent actions
Lets create a jsp page which calls the dispatch action classes in struts-config.xml

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

Quote:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<b><font color="Green">Tutorial Pruodly Presented by <a href="http://s2sgateway.com">http://s2sgateway.com</a></font></b><br>
<html:link page="/dispatch.jsp">dispatch</html:link>
<html:link page="/dispatch.do?parameter=tutorial">Tutorials</html:link>
<html:link page="/dispatch.do?parameter=downloads">Downloads</html:link>
</body>
</html>

In dispatch action.java file we can redirect the form using different functions, so we don't need to use default execute() method
[java lines="50"]

package com.s2sgateway.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.s2sgateway.form.DispatchForm;
public class DispatchAction1 extends DispatchAction {

public ActionForward tutorial(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

return mapping.findForward("tutorial");
}
public ActionForward downloads(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

return mapping.findForward("downloads");
}
}
In struts-config.xml we can define the forward name and path to be redirected

Quote:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="dispatchForm" type="com.s2sgateway.form.DispatchForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="dispatchForm"
input="/dispatch.jsp"
name="dispatchForm"
parameter="parameter"
path="/dispatch"
scope="request"
type="com.s2sgateway.action.DispatchAction1">
<forward name="tutorial" path="/tutorial.jsp" />
<forward name="downloads" path="/downloads.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.s2sgateway.ApplicationResources" />
</struts-config>

The other file named dispatch.java is doing a same function as index.jsp but it gets the parameter value in textbox rather than link
dispatchs2sgateway.

Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
Thumbs Up Struts hiberanate integration tutorial part2 rajasri 9 2,345 05-02-2012 04:29 PM
Last Post: admin
  Struts hiberanate integration tutorial part2 admin 1 689 05-02-2012 02:36 PM
Last Post: lalithakotha
  Login form authentication using Struts with database mjm 1 4,688 04-27-2012 03:57 PM
Last Post: alexrabe
Photo Simple Struts-Hibernate Integration tutorial to insert values rajasri 2 6,692 01-15-2012 01:40 PM
Last Post: mukesh1234
Sad Simple Struts Example rajasri 0 1,066 12-14-2011 11:17 AM
Last Post: rajasri
Photo How to export data as pdf in struts using displaytags rajasri 0 2,148 12-12-2011 06:38 PM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Like Our Facebook Page