Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to email a generated JSP page

 
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
 
Author and all-around good cowpoke
Posts: 13078
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
 
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.
 
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.
 
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
 
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
 
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
 
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone can post the piece of source code here?
 
author
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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!