By: Grenfel in Struts Tutorials on 2023年05月04日 [フレーム]
DispatchAction is a Struts Action class that helps in handling multiple requests in a single action. It is useful when a single Action class is needed to handle multiple related requests, which would otherwise require multiple Action classes.
To use DispatchAction in Struts, the following steps need to be performed:
Here's an example of how to use DispatchAction in Struts:
public class MyDispatchAction extends DispatchAction {
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// Add logic here
return mapping.findForward("success");
}
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// Edit logic here
return mapping.findForward("success");
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// Delete logic here
return mapping.findForward("success");
}
}
In the struts-config.xml file, the new Action class can be mapped like this:
<action path="/myAction" type="com.example.MyDispatchAction"> <parameter name="method" value="add" /> <parameter name="add" value="com.example.AddForm" /> <forward name="success" path="/success.jsp" /> </action>
In this example, the "method" parameter is used to determine which method to invoke in the MyDispatchAction class. The "add" parameter specifies the form bean to use for the "add" method. The "success" forward is used to navigate to the success.jsp page after the action is performed.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Struts )
Handling Duplicate Form Submissions in Struts
Configuring JDBC DataSources in Struts
Simple example of using the requiredif Validator rule in Struts
Using JavaScript to submit a form in Struts
When is the best time to validate input in Struts
How to prepopulate a form in Struts
Guidelines for Struts Application Development
Latest Articles (in Struts)
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Configuring JDBC DataSources in Struts
When is the best time to validate input in Struts
Simple example of using the requiredif Validator rule in Struts
How to prepopulate a form in Struts
Using JavaScript to submit a form in Struts
FAQ: Why are my checkboxes not being set from ON to OFF?
FAQ: Why was reload removed from Struts (since 1.1)?
Handling Duplicate Form Submissions in Struts
Guidelines for Struts Application Development
Configuring JDBC DataSources in Struts
When is the best time to validate input in Struts
Simple example of using the requiredif Validator rule in Struts
How to prepopulate a form in Struts
Using JavaScript to submit a form in Struts
FAQ: Why are my checkboxes not being set from ON to OFF?
FAQ: Why was reload removed from Struts (since 1.1)?
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate