Tutorial Home
Hibernate
StrutsJSP
Spring
|
Struts Tutorial -- Code ExamplesDispatchActionDispatchAction is another useful built-in Struts Action.Use DispatchAction when a set of actions is closely related and separating them into multiple Actions would result in duplication of code. For example : If there are three operation like delete, activate, deactivate employee. You can create three different Actions – ActivateEmpAction, DeleteEmpAction and DeActivateEmpAction. This is a valid approach, although not elegant since there might be duplication of code across the Actions since they are related. DispatchAction is the answer to this problem. With DispatchAction, you can combine all three Actions into one. Follow the below five steps to setup DispatchAction. Step 1. In the JSP page (empdetails.jsp)
Step 2. Adding ActionForm Entry in struts-config.xml Add the following entry in the
struts-config.xml file.
Step 3. Add action mapping in the struts-config.xml file: Add the following action mapping in the
struts-config.xml file: Step 4. In the Action class. Step 5. In the EmpForm Now in the browser type http://localhost:8080/app/jsp/empdetails.jsp
In the above
example DispatchAction was used handle hyperlinks. DispatchAction is
a good choice when there are form submissions using the regular buttons . Just name all the buttons same.
<html:submit property="step">Delete</html:submit>
<html:submit property="step">Activate</html:submit>
<html:submit property="step">Deactivate</html:submit>
|
|
SCJP 6.0 Simulator 664+ Questions With Explanations
SCWCD 5.0 Simulator 556+ Questions With Explanations
SCWCD 4.0 Simulator 500+ Questions With Explanations
OCA 10g Simulator 594+ Questions With Explanations
Hiring made easy Harness social networking, employee referrals, Agency portal and Job Portals