Sunday, November 8, 2009

Handling double form submission problem with Struts

An optimal solution for resolving double form submission problem using Struts:

DispatchStrutsAction
--------------------
package com.myapp.struts;

public class DispatchStrutsAction extends DispatchAction {
private final static String LOGINSUCCESS = "loginsuccess";
private final static String LOGINPAGE = "loginpage";


public ActionForward beforeLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
this.saveToken(request);//save token before showing Login.jsp
return mapping.findForward(LOGINPAGE);
}
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(this.isTokenValid(request)){
resetToken(request);
}else if(!this.isTokenValid(request)){
System.out.println("Page Resubmit");
}
return mapping.findForward(LOGINSUCCESS);
}
}

2 comments:

  1. Dear Techie,
    Please explain what is double form submit problem.
    Is it about clicking the submit button twice by mistake?

    ReplyDelete