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
Joined: Mar 22, 2000
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
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.
Joined: Oct 09, 2001
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.
Joined: Nov 22, 2008
Just as well it was only a typing error, and not a spelling mistake.
Joined: Sep 10, 2001
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
Joined: Jan 30, 2002
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
hi chris , please do me a favour by mail the code to me too at email@example.com .I also want to do something like u have done. thanx in advance........ regards.. apurva
Joined: Jan 08, 2001
Chris, sounds very interesting. Why too long? Please post it here.
Joined: Mar 12, 2002
anyone can post the piece of source code here?
Joined: Nov 07, 2000
"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