By: Ivan Lim in Struts Tutorials on 2023年05月04日 [フレーム]
Handling Duplicate Form Submissions is an important aspect of web application development, as it helps to prevent accidental or intentional repeated submission of the same form data. Struts provides some built-in support for handling duplicate form submissions, which can be implemented using the following steps:
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <html:form action="/submitForm.do"> <html:hidden property="token"/> <!-- Other form fields --> <html:submit value="Submit"/> </html:form>
public class MyActionForm extends ActionForm {
private String token;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
public class MyAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
MyActionForm myForm = (MyActionForm) form;
String token = myForm.getToken();
// Validate the token
if (!isTokenValid(request)) {
// Duplicate form submission
return mapping.findForward("duplicate");
}
// Process the form data
// ...
// Reset the token to prevent duplicate form submission
resetToken(request);
// Return success forward
return mapping.findForward("success");
}
}
<form-beans> <form-bean name="myForm" type="com.example.MyActionForm"/> </form-beans> <action-mappings> <action path="/submitForm" name="myForm" type="com.example.MyAction" scope="request"> <forward name="success" path="/success.jsp"/> <forward name="duplicate" path="/duplicate.jsp"/> </action> </action-mappings>
The above steps will help in preventing duplicate form submissions in Struts. It is important to handle duplicate form submissions, as it can lead to unwanted processing of the same data, which can cause data inconsistency and other issues.
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