![]() |
|
Struts Dispatch Action Tutorial with example - Printable Version +- WalkinsForum-Jobs,Job Openings,Daily Walkins,Weekend Walkins,Vacancies,Off campus,Interviews Forum (http://www.walkinsforum.com) +-- Forum: Programming Forum (/Forum-programming-forum) +--- Forum: Java (/Forum-java) +---- Forum: struts tutorial (/Forum-struts-tutorial) +---- Thread: Struts Dispatch Action Tutorial with example (/Thread-struts-dispatch-action-tutorial-with-example) |
Struts Dispatch Action Tutorial with example - rajasri - 12-12-2011 08:56 PM 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"> 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"?> 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
|