• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How can I capture the output of a JSP file and send an email?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I capture the output of a JSP file and send the generated html output 'as is' by email.
My application shows the report in a html format. when the user clicks the link "Send as Email" it should send the output as seen by the user to a predefined mail id. (The html text generated should be sent by email) So that the user sees exactly what he has seen through the web browser in the email.
How this can be achieved?
Thank you,
Shaji
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Shaji!
Well, I believe that I have one solution for that, and I hope it can be useful for you.
I will suppose you can easily send emails using the java.mail.stuff, so we'll be able to focus the "how to capture the jsp output" part of the problem.
In order to make it simpler to understand, let's call the result you want sent by email "Page A". That may be a simple jsp page, a servlet url... You got the idea.

Next, you'll need the EmailSender part, that could be a servlet, or a (Struts) action (they work basically the same way).
One possibility is having a map already created with the page you want (A) and whatever you want to call it ("report_A"). That wouls be just as useful as passing the url as a parameter, but will be gently harder to code(/mantain).
A simpler way is sending the html_content of your email as a parameter (not the CODE itself, but the url we previously called PAGE A).

Let's see what I can do on a virtual code here:

Please note that this functionality can also help you create "printer friendly" versions of what you need, and customising that for an "email friendly" would be just as easy.

HTH,
Gus
[ December 30, 2003: Message edited by: Gustavo Torreti ]
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do we have any good tutorial giving us a practical scenario as to when to use the stringBuffer, streamReader and other such classes. I always get confused as to when to used what type of class. I see them being used extensively in generating the servlet response.
Thanks for any advice.
 
Gustavo Torreti
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Jayadev,
I'll tell you what I lived and learned; Let's hope it can give you some clues for you with real-world "practical scenarios".

The StringBuffer class is basically what it says it is (a buffer for string). That means you should use it when you got a lot of string manipulation, cutting, pasting, appending new words. If you remember the old lost basics (the String stuff that is covered by scjp), a String cannot be changed, so when you do some code like

you actually create a third string object "my New String Test". Although it might not be such a bad idea in a couple of objects, consider the String manipulation used on a long servlet response, or perhaps on this little for loop:

Up here, I counted 104 String objects that could be easily use no more than 4; Consider the ammout of work to the JVM to create and then destroy all these objects. Consider you may run your app on a heavy-duty machine that doesn't have the time, RAM nor CPU to waste with that.
The loop example over here WORKS. And it works fine. When you speak of StringBuffer, however, It shows a concern of optimization included in your work.
The [Buffered]StreamReader and writers are supposed to help you in different ways, but always doing part of the hard work for you. Java have got plenty of this I/O stuff, so it is possible that, no matter what you need, there's something in there you can use.
I can give you two main reading materials to that, if that is also what you want:
- The Java Tutorial (downloadable through java.sun.com) // IO Stuff
- The SCJP&D study book by Kathy and Bert(http://www.amazon.com/exec/obidos/tg/detail/-/0072226846/qid=1072782357/sr=1-1/ref=sr_1_1/103-0067155-1028648?v=glance&s=books) // I think there's still IO in there, and also the StringBuffer.

HTH,
Gus
[ December 30, 2003: Message edited by: Gustavo Torreti ]
[ December 30, 2003: Message edited by: Gustavo Torreti ]
 
Shaji Kalidasan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gustavo, It worked and I am able to send the mail, the way everyone wanted.
Thanks once again for this wonderful solution.

Originally posted by Gustavo Torreti:
Hello, Shaji!
Well, I believe that I have one solution for that, and I hope it can be useful for you.
I will suppose you can easily send emails using the java.mail.stuff, so we'll be able to focus the "how to capture the jsp output" part of the problem.
In order to make it simpler to understand, let's call the result you want sent by email "Page A". That may be a simple jsp page, a servlet url... You got the idea.

Next, you'll need the EmailSender part, that could be a servlet, or a (Struts) action (they work basically the same way).
One possibility is having a map already created with the page you want (A) and whatever you want to call it ("report_A"). That wouls be just as useful as passing the url as a parameter, but will be gently harder to code(/mantain).
A simpler way is sending the html_content of your email as a parameter (not the CODE itself, but the url we previously called PAGE A).

Let's see what I can do on a virtual code here:

Please note that this functionality can also help you create "printer friendly" versions of what you need, and customising that for an "email friendly" would be just as easy.

HTH,
Gus

 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gustavo. That was very helpful info.
 
Gustavo Torreti
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Always a pleasure.
G
 
What? What, what, what? What what tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic