Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pop up for new mail - mail application

 
Anu Pasricha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am developing an intranet mailing system,For which i want to create a servlet which checks for a new mail (new record in mail table) every 5 min, and if the reciever is logged in, the servlet should pop up a window stating new message arrival.
How should i go about it???
Anu
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
what have you got so far ?
the servlet can not just pop up a window on the client side. HTTP is a request response protocol. the servlet (the server) only sends data to the client when it received a request from a browser (the client)
you would need the client to reload a page every 5 minutes (javascript). depending on the state (new mail or not ) different pages are loaded (the normal page and one that additionally will pop up a "new mail arrived" window)
k
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can set a refresh header to reload your page every 5 minutes to make the work, or you can also
run a thread which will check
your table every 5 minutes.
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a same thing in one of my application. Your question could be divided into two questions
1) How to make a Servlet refresh every 5 mins?
This could be done by setting the Header attribute. This way the Servlet will get refreshed every 5 mins
2) How to display a new mail pop up?
The best and easy way to do this using the JavaScript. Have a Javascript function that does a pop window. Call that JavaScript function inside the BODY tag for "onLoad" . Enclose this "Onload" logic inside a "if" condition that checks whether new mail is present. This new mail present attribute will be set by the Servlet directing to this JSP.
I hope you get the idea
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>you can also run a thread which will check
> your table every 5 minutes.
How to do that? By running an object on the server side? if so, how it call the client for new mail??
 
Rikard Qvarforth
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an ide is to make the client (a java progg running i tray maby) pull the server for new emails but the best way is if you make a socket connection so the server tells the client when new mails have arrived. check out JTray and desktopindicator hope it helps
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi anu,
its very easy to have a mail popup..
i will tell u the way i have done this.
Divide the home page into frames.
let it has
. a top frame ( some links like back,logout)
. a left frame (for menu components)
. middle frame (for displaying the pages)

now divide the left frame into two
top frame with menu components
bottom frame for popup.
refresh the jsp (left bottom frame) every 1 or 2 minutes..u can find the java script code for page autorefresh on internet.check www.dynamicdrive.com
and in the jsp add a scriptlet to check if any new messages in the inbox
hmmm...i wll write the code
<%@ page import='CheckMailBean' %>
<% CheckMailBean mailbean = new CheckMailBean();
int newmail = mailbean.checkInbox(myID);
System.out.println("newmail = " + newmail);
String popup = null;
if (newmail > 0 )
{ popup = "<script> alert('new mail'); </script> ";
}
else
{ System.out.println("new mail count is ZERO");
}
%>
print that variable "popup" at the end of the jsp page after the </body> tag.. u can find codes for popup script on the above mentioned site .
is it clear..easy naa ???
raj

SCJP2
 
Anu Pasricha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot.
I have implemented the same using thread.
I have created a thread in login page, and the thread starts when login is correct.
The thread's run method checks for the condition and if new mail has arrived then instantiate a class which i extended from frame.
Regards,
Anu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic