Documente Academic
Documente Profesional
Documente Cultură
package roseindia.net;
/**
* @author Amit Gupta
* @Web http://www.roseindia.net
* @Email struts@roseindia.net
**/
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");
}
Here, we need to create multiple independent actions for each method defined in the
action class. Note that the value specified with the parameter attribute is used to
delegate request to the required method of the MappingDispatch_Action Class.
<action path="/MappingDispatchAction"
type="roseindia.net.MappingDispatch_Action"
parameter="add"
input="/pages/MappingDispatchAction.jsp"
scope="request"
validate="false">
<forward name="add" path="/pages/MappingDispatchActionAdd.jsp" />
</action>
<action path="/MappingDispatchAction"
type="roseindia.net.MappingDispatch_Action"
parameter="edit"
input="/pages/MappingDispatchAction.jsp"
scope="request"
validate="false">
<forward name="edit" path="/pages/MappingDispatchActionEdit.jsp" />
</action>
<action path="/MappingDispatchAction"
type="roseindia.net.MappingDispatch_Action"
parameter="search"
input="/pages/MappingDispatchAction.jsp"
scope="request"
validate="false">
<forward name="search" path="/pages/MappingDispatchActionSearch.jsp"/>
</action>
<action path="/MappingDispatchAction"
type="roseindia.net.MappingDispatch_Action"
parameter="save"
input="/pages/MappingDispatchAction.jsp"
scope="request"
validate="false">
<forward name="save" path="/pages/MappingDispatchActionSave.jsp" />
</action>
</html:html>
<li>
<html:link page="/pages/MappingDispatchAction.jsp">Struts File Upload</html:link>
<br>
Example demonstrates how MappingDispatchAction class works.
</li>
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 MappingDispatchAction.jsp page. Your browser displays the following
MappingDispatchAction page.
Selecting Call Add Section displays the following MappingDispatchActionAdd.jsp
page