aspose file tools*
The moose likes JSP and the fly likes How to email a generated JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to email a generated JSP page" Watch "How to email a generated JSP page" New topic
Author

How to email a generated JSP page

First Light
Greenhorn

Joined: Nov 27, 2000
Posts: 14
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

Joined: Mar 22, 2000
Posts: 12821
    
    5
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Oct 09, 2001
Posts: 566
This has been very sucessful for my puposes.

for your porpoises?
[ February 12, 2002: Message edited by: Adam Hardy ]

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Just as well it was only a typing error, and not a spelling mistake.
Patricia Fulk
Ranch Hand

Joined: Sep 10, 2001
Posts: 62
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

Joined: Jan 30, 2002
Posts: 22
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

Joined: Sep 10, 2001
Posts: 62
Thanks Christopher! If you could email the code that would be great. patriciafulk@yahoo.com
apurva mehta
Ranch Hand

Joined: Nov 21, 2001
Posts: 35
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

Joined: Jan 08, 2001
Posts: 2164
Chris,
sounds very interesting.
Why too long?
Please post it here.
dannypub
Greenhorn

Joined: Mar 12, 2002
Posts: 1
anyone can post the piece of source code here?
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to email a generated JSP page