code: public static HttpResponseException success(final String destination) {
          return new HttpResponseException() {
              public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
                  if (isApply(req)) {
                      // if the submission is via 'apply', show a response in the notification bar
                      applyResponse("notificationBar.show('"+Messages.HttpResponses_Saved()+"',notificationBar.OK)")
                              .generateResponse(req,rsp,node);
                  } else {
                      rsp.sendRedirect(destination);
                  }
              }
          };
      }
docs: Generates the response for the form submission in such a way that it handles the "apply" button
  correctly.
  
  @param destination
  The page that the user will be taken to upon a successful submission (in case this is not via the "apply" button.)