JSP Method for Repeated Submission of Forms

  • 2021-08-31 08:48:11
  • OfStack

In this paper, an example is given to describe the processing method of JSP for repeated submission of forms. Share it for your reference, as follows:

1. Perform the following when generating the form:

session.setAttribute("forum_add", "forum_add");

2. Make the following judgment when submitting for processing


if (isRedo(request, "forum_add")) {
 // Prompt for repeated submission , Make relevant treatment 
}

Correlation function:


/**
*  Determine whether it is a duplicate submission 
* 1 , check Session Contains an attribute with the specified name in 
* 2 , if Session If there is no attribute in or the attribute is empty, it proves that it has been processed and it is judged as repeated submission 
* 3 Otherwise, the proof is the first 1 Is processed, and the property is changed from the Session Delete from. 
* @param key String
*/
private boolean isRedo(HttpServletRequest request, String key) {
  String value = (String) request.getSession().getAttribute(key);
  if (value == null) {
   return true;
  }
  else {
   request.getSession().removeAttribute(key);
   return false;
  }
}

I hope this article is helpful to everyone's JSP programming.


Related articles: