11:01 am - Thursday April 27, 2017

struts 1x Mapping Dispatch Action with example program In Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

MappingDispatchAction Class 

  • In MappingDispatchAction we will use more methods to control more action,one controller,more view page.
  • For example  will use more link in one page like calladdsection, calldeletesection, callupdatesection to control one controller and more view page.
  • In this class UserAction extends               org.apache.struts.actions.MappingDispatchAction. Normal Action class invoke execute() method. But in this class not invoked execute() method. It will be  invoked separate method  like as method=”add” ,method=”delete”, method=”update”  which  the method  will be use the parameter in the view page.Here we have to use separate view page for each method.


Step by Step tutorial on running  your  Mapping Dispatch Action Struts application in Tomcat5.5 with Eclipse IDE

Step – 1 Creating Dynamic web Project

Step – 2 Mapping Dispatch Action STRUTS folder structure

Step – 3 Creating your Mapping Dispatch Action Struts program(Controller & Model)

Step – 4 Creating web.xml for Mapping Dispatch Action struts application

Step – 5 Creating Struts-config.xml

Step – 6 Mapping Dispatch Action  Struts view page

Step – 7 How to Add server in  Mapping Dispatch Action Struts application

Step – 8 OutPut  for  Running  Mapping Dispatch Action  Struts application

 SOURCE CODE

Step – 1 Creating Dynamic web Project

Start Eclipse and goto File -> New -> Project -> Dynamic Web Project

 

Following is the list of required JAR files to be added in Java Class Path of your project. Download displaytag JAR files from 

JAR FILES + TLD FILES

Step – 2 Mapping Dispatch Action STRUTS folder structure

 lib folder

Download The Following TLD files  and paste into WEB-INF

Step – 3 Creating your Mapping Dispatch Action Struts program(Controller)

MappingDispatch_Action.java

package Com.Candidjava;

import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.struts.actions.MappingDispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class MappingDispatch_Action extends MappingDispatchAction {

	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("You are in add function.");
		return mapping.findForward("add");
	}

	public ActionForward edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("You are in edit function.");
		return mapping.findForward("edit");
	}

	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("You are in search function");
		return mapping.findForward("search");
	}

	public ActionForward save(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("You are in save function");
		return mapping.findForward("save");
	}

}

Step – 4 Creating web.xml for Mapping Dispatch Action struts application


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

	<display-name>Struts Blank Application</display-name>

	<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>
		<init-param>
			<param-name>debug</param-name>
			<param-value>2</param-value>
		</init-param>
		<init-param>
			<param-name>detail</param-name>
			<param-value>2</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>

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

	<welcome-file-list>
		<welcome-file>MappingDispatchAction.jsp</welcome-file>
	</welcome-file-list>
	<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>

Step – 5 Creating Struts-config.xml

Struts-config.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

	<action-mappings>
		<action path="/MappingDispatchActionAdd" type="Com.Candidjava.MappingDispatchActions"
			parameter="add" input="/MappingDispatchAction.jsp" scope="request"
			validate="false">
			<forward name="add" path="/MappingDispatchActionAdd.jsp" />
		</action>

		<action path="/MappingDispatchActionEdit" type="Com.Candidjava.MappingDispatchActions"
			parameter="edit" input="/MappingDispatchAction.jsp" scope="request"
			validate="false">
			<forward name="edit" path="/MappingDispatchActionEdit.jsp" />
		</action>

		<action path="/MappingDispatchActionSearch" type="Com.Candidjava.MappingDispatchActions"
			parameter="search" input="/MappingDispatchAction.jsp" scope="request"
			validate="false">
			<forward name="search" path="/MappingDispatchActionSearch.jsp" />
		</action>

		<action path="/MappingDispatchActionSave" type="Com.Candidjava.MappingDispatchActions"
			parameter="save" input="/MappingDispatchAction.jsp" scope="request"
			validate="false">
			<forward name="save" path="/MappingDispatchActionSave.jsp" />
		</action>

	</action-mappings>

</struts-config>

Step – 6 Mapping Dispatch Action  Struts view page 

MappingDispatchAction.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html-1.1.tld" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Mapping Dispatch Action Example</title>
</head>
<body bgcolor="pink">
<H3>Mapping Dispatch Action Example</H3>
<p><html:link page="MappingDispatchActionAdd.do?parameter=add">Call Add Section</html:link></p>
<p><html:link page="MappingDispatchActionEdit.do?parameter=edit">Call Edit Section</html:link></p>
<p><html:link page="MappingDispatchActionSearch.do?parameter=search">Call Search Section</html:link></p>
<p><html:link page="MappingDispatchActionSave.do?parameter=save">Call Save Section</html:link></p>

</body>
</html>

MappingDispatchActionAdd.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor=" pink">
Mapping DispatchAction Add
</body>
</html>

MappingDispatchActionEdit.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Mapping DispatchAction Edit
</body>
</html>

MappingDispatchActionSave.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Mapping DispatchAction Save
</body>
</html>

MappingDispatchActionSearch.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Mapping DispatchActionAdd
</body>
</html>

Step – 7 How to Add server in  Mapping Dispatch Action Struts application

Window –>show view—->servers—.add new–>          

Select ther version which you installed in your System

How to run the Project:

Right click on project name———->click Run As —> Run On Server 

Step – 8 OutPut  for  Running  Mapping Dispatch Action  Struts application

DOWNLOAD+SOURCE CODE                                                                                                                                                                                                                 BACK

Filed in: Z-AStruts Codes

No comments yet.

Leave a Reply