Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to email a generated JSP page

 
First Light
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am generating a simple report using JDBC and formatting the data and displaying it as a jsp file but besides displaying the page, I also would like to be able to email the very same page to someone else. Is there a way to access the contents of the page after it is generated? I do not want to modify the code to write everything onto a file and then email/and or display it. Is there a better way to do it?
Any suggestions welcome.
thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the contents of a JSP are written to the HTTP response, the simplest way to trap them is to create a request URL and send it to the web server, then grab the response. Look into the java.net.URLConnection and HttpURLConnection classes.
Bill
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From another perspective:
I've recently done a similar thing, but I've created a subclass from BodyTagSupport. This provides a BodyContent() object that gives you access to the JspWriter buffer (from memory via the getString() method). The BodyContent also offers getReader() method as well.
From these classes/methods you can retrieve the entire response being sent to a browser.
This has been very sucessful for my puposes.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been very sucessful for my puposes.

for your porpoises?
[ February 12, 2002: Message edited by: Adam Hardy ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as well it was only a typing error, and not a spelling mistake.
 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am faced with a similar situation. I am assuming that tags are being used since BodyTagSupport is being subclassed. Can someone give an example of how to implement the tag. I am quite new with tags.
Thanks,
Trish
 
Christopher Dixon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also had success with creating a class that implements HttpServletResponse to wrap the true HttpServletResponse object provided by the container. Most of the calls are passed through (sendRedirect, addHeader, etc) but overriding the getWriter() method (and all the associated methods - flush, close, etc) to work on my own PrintWriter. To obtain the output, create an instance of the Adapter and pass it to RequestDispatcher.include(request, wrappedResponse).
I believe you could also do something similar with the 2.3 Filtering API, if you have that available in your container.
I have the code, if you'd like it. I think it's too long to post here.
Chris
 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christopher! If you could email the code that would be great. patriciafulk@yahoo.com
 
apurva mehta
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi chris ,
please do me a favour by mail the code to me too at apurvamehta1@rediffmail.com .I also want to do something like u have done.
thanx in advance........
regards..
apurva
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
sounds very interesting.
Why too long?
Please post it here.
 
dannypub
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone can post the piece of source code here?
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"First Light"
Thanks for participating here at the Ranch. However, the name you are using does not comply with the naming convention described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name (not fictitious monikers). Please log in with a new name which meets the requirements.
Thanks.
Sean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic