• Post Reply Bookmark Topic Watch Topic
  • New Topic

execute the jsp code after every 10 seconds kindly provide me the code  RSS feed

 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, All,

I want to execute my jsp code to compare two dates after every 10 seconds if user enter date and current sys date are equal it will send the mail to the user automatically. kindly provide me the code i am not able to write the code , below is my jsp code

 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all avoid writing java codes inside jsp, its a very old practice. Try to write these codes in servlet with some helper classes. Now coming to your question where from are you getting these two inputs?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ExpcReDt in this variable i am taking Date from user dateStr is system current date and i am comparing ExpcReDt with dateStr
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean, there is page where the user is entering the date and that page submits the request to this jsp page?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am taking user input from html and that page submit request to this page
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, as soon as the user submits request, your server side code triggers, right and it depending upon the condition it sends the mail? Then what is that 10 seconds got to do?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to check the below condition every 10 seconds so that when ExpcReDt date and dateStr sys date are equal it will send the mail automatically For Ex. If ExpcReDt ="26-2-2014" and today's Current Sys Date ="25-2-2014 So when both dates are equal it will send the mail accordingly , i want this condition to check the dates every 10 seconds

if(ExpcReDt.compareTo(dateStr)>0)
{
out.println("Expected return date is greater than current date");
}
else if(ExpcReDt.compareTo(dateStr)==0)
{
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might be wrong, and there can be better suggestions to this. But as per my understanding as soon as you get the request from client, you store this data in a queue(table/or some memory variable). You should have another servlet that runs in background in a different thread and executes at an interval of every 10 seconds. What this background servlet will do is, it will check what date I have in the queue. If the condition is satisfied it sends the mail and deletes that record from that queue.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This shouldn't be a JSP. A java.util.TimerTask started in the context listener of your web app might be a possibility, but we don't have enough detail to say for sure.

Where do ExpcReDt and dateStr come from? And how do they relate to the 10 seconds you mention? Surely the user does not enter a new date every 10 seconds?
 
Priyanka Dande
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here user is entering the date for the first time only i have to check two dates in the background continuosly so that when two dates are equal it will send the mail to the user , kindly provide me the code
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People here will not write the code for you, but will try to help you write the code yourself.

The servlet to which the form is submitted can use the java.util.Timer and TimerTask classes to create a background job that runs every X seconds. But since I assume the email should only be sent once (and not every 10 seconds after the condition becomes true, as it would be with the code you posted earlier), you should create a one-time job that runs at the time when the email should be sent. Timer/TimerTask can be used for that, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!