It's not a secret anymore!
The moose likes Servlets and the fly likes pop up for new mail - mail application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "pop up for new mail - mail application" Watch "pop up for new mail - mail application" New topic

pop up for new mail - mail application

Anu Pasricha

Joined: Jul 08, 2002
Posts: 13
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???
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
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)
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
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.

Asher Tarnopolski
Siva Jagadeesan
Ranch Hand

Joined: Oct 31, 2000
Posts: 160
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

Rgds<p>--Siva Jagadeesan<br /><a href="" target="_blank" rel="nofollow"></a><br />Sun Certified Java2 Programmer<br />Sun Certified Web Component Developer<br />BEA Certified Weblogic Server 7 Enterprise Developer
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
>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??

Thanks everyone who helped me
Rikard Qvarforth
Ranch Hand

Joined: Jul 10, 2001
Posts: 107
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

Joined: Aug 27, 2002
Posts: 455
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
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> ";
{ 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 ???


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Anu Pasricha

Joined: Jul 08, 2002
Posts: 13
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.
I agree. Here's the link:
subject: pop up for new mail - mail application
It's not a secret anymore!