• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to avoid second request when the server is processing first request

 
sentil kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
form.jsp

<form action="handle.jsp" method="post">
FirstName<input type="text" name="fname">
<input type="submit">
</form>


handle.jsp
<%
response.setContentType("text/html");

System.out.println("servlet1......");
out.println("<h1> page start</h1>");

String param = request.getParameter("fname");
application.log(param);
for(int i = 0; i < 10000; i++){
application.log("servlet ..."+param+i);
System.out.println("servlet1......"+param+i);
}
out.println("<h1> page end</h1>");
%>

i have requested the form.jsp
http://localhost:8080/test/form1.jsp

i have given hello as a value in the text field then submit the form and
again submit the form when the first request is still processing by server.

please run the above sample code and see the server is executing the same funtion for two same request.

how to avoid the second submit when the server is processing the first submit still.
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are various options:
1. Disable the submit button after user clicks on Submit using javascript.

2. Use Struts framework. Use the Token methods provided by Struts to prevent duplicate submits. It provides a clean approach to handle this issue.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sunil,


With solution provided by you>>
What happens if 10 users submit the request at the same time.

I have a costly solution: submit the requested to another Storeservlet;

Where in it will store the request and response objects in a (say)50x2 array.and put it into context.
put the count which index you are passing...use synchronised method to increment the position. put it into context;

and forward(arr[count][0],arr[count][1]) it to the actual servlet.
when ActualServletStatus = true.

Important point: put another variale in context indicating servlet1 is ready or not. for this Put Boolean ActualServletStatus = true.

So before you start service of actual servlet do
Synchronised(Context) { and
set ActualServletStatus = false;
}
After finishing the service
Synchronised(Context) { and
set ActualServletStatus = true;
}

I have given a outline... you can expand it.


Lets Rock

[ March 09, 2007: Message edited by: Srinivasan thoyyeti ]
 
sentil kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sunil,
Please give a reference link for the struts approach

Thanks in Advance.
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you have a background of struts. If not, please read through Struts documentation under http://struts.apache.org/

As a quick reference, you can have a look at: http://www.javaworld.com/javaworld/javatips/jw-javatip136.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic