• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets, emails and Servlets......

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have written a little program which takes in data, manipulates it and writes it to a text file but i have a little problem getting it to do a few more things.
Basically i have my bookingServlet which takes in a few parameters from a jsp page, the client then enters their details and this sends their data along with the manipulated jsp data to receivedServlet which then manipulates the data and writes to a text file and has some dynamic text on it.
What i would like to do is when i press submit from bookingServlet my little program also emails my form data to someone but still ends up at my receivedServlet where i can do my data writing. Is this possible??? Can i have 2 actions, one to a cgi-bin and one to my servlet or is there a better way to do this. Unfortunately i don't have access to a database and am not too hot on ASP.
Any help would be appreciated.
Thanks
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could handle the emailing in the same servlet as you are writing the file. The JavaMail API provides a very convienient way to send mail via SMTP etc. Otherwise you could do it manually by opening up a URLConnection to the cgi-bin program and passing the request parameters to it.... this would be a quick and dirty way to do it though.
Cheers
Sam
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can certainly compose and send email from a servlet with the JavaMail API. Because sending mail requires the cooperation of a mail server, you have to handle situations in which the mail server is slow, not up right now, etc. without causing your sevlet to hang.
I suggest you have the servlet pass the mail to a separate object running its own Thread.
Bill
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer to use JMS rather than spawning my own threads to achieve asychronous processing. From the servlet (or a filter if you want to seperate out concerns fully) I would use JMS to put the mail information into a message and onto a queue, before processing the rest of the servlet. Create a seperate Message Driven Bean which listens to this queue and processes the messages in its own time, using Java Mail.
Paul
 
Sam Tilley
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for the great (and quite distinguished) feedback, ill have a look at the different options and see how i get on.
[ January 08, 2003: Message edited by: Sam Tilley ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah - JMS is cool and can be made to persist the messages in case the server goes down. Which implementation do you use Paul?
Bill
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>I suggest you have the servlet pass the mail to >a separate object running its own Thread.
Do you know any sample source code for opening a separate Thread doing tasks?Thanks
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is really pretty straightforward, a class that implements Runnable. You create an instance with a Thread that has a low priority. The run method sleeps for some reasonable amount of time, when it wakes up, it looks to see if somebody has left it a job in a Vector or similar collection. Naturally you have to pay close attention to synchronization.
Bill
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic