0

I have a problem in java Servlet. Suppose i have two Servlet and two page(jsp). In index.jsp client enter your mobile number and submit form to sendSMS.do. sendSMS.do must be send SMS to mobile number.

servlet 1: index.do

page 1: index.jsp

servlet 2:sendSMS.do

page2 : success.jsp

in index.jsp :

<form action="/sendSMS.do" method="post">
    <input type="text" name="mobile">
    <input type="submit" value="sendSMS">
</form>

in sendSMS.do:

@WebServlet("/sendSMS.do")
public class RegisterController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      String mobileNUmber=req.getParameter("mobile");
      SendMessage sendMSG= new SendMessage();
      //if there are network problems,sendSMS method my be take several minutes for return false
      sendMSG.sendSMS(mobileNumber);
      resp.sendRedirect("/success.jsp");
    }
}

So sendSMS method return true if there is not any problem else return false after several minutes.If client in index.jsp page multiple click on submit button, there are several same request in server.

So How to detect this same request and is there any best practice for this issue?

I read Solving the Double Submission Issue but i want best practice when Servlet take long time to response.

Thanks in advice.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • you can just disable the client action while in the process – johnjerrico Sep 04 '17 at 07:41
  • I want do this in server side no client side. I know i can disable button submit – user6920966 Sep 04 '17 at 07:54
  • do you have any way to identify this user ? if your server is an api .. I usually use token, thus I can log this user request; if not use session – johnjerrico Sep 04 '17 at 08:07
  • I can use session attribute for detect this issue but i want another way because my pages more than 1. – user6920966 Sep 04 '17 at 10:02
  • I don't see any problems, since u can log the user action on each pages, along with timestamps & status so that you could check it against the current request.. however if you are concern about the concurrency problem maybe it would be simpler to store it into database (since it provide locking mechanism out of the box) – johnjerrico Sep 05 '17 at 03:21
  • Thanks @johnjerrico – user6920966 Sep 12 '17 at 03:53

0 Answers0