aspose file tools*
The moose likes Servlets and the fly likes Saving an HTML file generated by the JSP on the Server - Possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Saving an HTML file generated by the JSP on the Server - Possible?" Watch "Saving an HTML file generated by the JSP on the Server - Possible?" New topic
Author

Saving an HTML file generated by the JSP on the Server - Possible?

Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
How do I save the HTML file generated by the JSP on the server.I want to save the file and send it as an attachment to the mail.
Is it possible to write some code in JSP which does this.
Thanks in advance,


------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Desai Sandeep:
How do I save the HTML file generated by the JSP on the server.I want to save the file and send it as an attachment to the mail.

One way to do this is to use URL.getContent() to generate a request to the JSP and capture the generated content in a String. Not terribly efficient, but easy and for most purposes it will do fine.
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Peter,
Could you elaborate on this.If possible please paste a code for this.
Thanks in advance.
Regards,
------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Just off the top of my head, so it's guaranteed not to work:

Good luck
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Peter,
I have doing some research on this for sometime now.I had received some suggestions that it can done using one of the three methods.

  1. Filtering added in Servlet 2.3 specification
  2. Custom tag implementing the BodyTag interface
  3. URLConnection

  4. The third solution is what probably you have mentioned.Does this mean using Serialization and writing it to a file using the ObjectOutputStream, and then reading it when required using the ObjectInputStream.
    About the first 2 methods, I still have no clue.Any advise on this would be highly appreciated.
    Thanks in advance.
    Regards,


    ------------------
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
it is very easy to get the html content generated by the servlet ..
one way is to as below ..
try
{
URL u = new URL(strUrl);
InputStream i = u.openStream();
//now u have the inputstream ..u can do anything ..like writing to the file
}
catch(Exception e){}
hope it might help
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Prabhat,
That is right!!I guess to do it using URLConnection is one of the ways to do it.
However, I also wanted to explore the other possible methods :

  • Filtering added in Servlet 2.3 specification
  • Custom tag implementing the BodyTag interface

  • Any ideas on this?
    Thanks in advance,

    ------------------
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
I havent tried with filtering....but this link has good explanation on Filters.
Anil


SCJP 1.5, SCEA, ICED (287,484,486)
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Desai Sandeep:

  1. Filtering added in Servlet 2.3 specification
  2. Custom tag implementing the BodyTag interface
  3. URLConnection

  4. The third solution is what probably you have mentioned.Does this mean using Serialization and writing it to a file using the ObjectOutputStream, and then reading it when required using the ObjectInputStream.

To start with your last remark, yes, that's what I suggested (as the javadoc points out, URL.getContent() is just shorthand for URL.openConnection().getContent()). But serialization -- you want to capture a JSP's HTML output, right? So it's just plain text. Object serialization doesn't enter the picture as far as I can see.
About the other two solutions, not quite sure. Filtering is quite new and your server may not support it, also it's not clear to me how it would help.
Tag libraries are well supported, but wouldn't that mean embedding your HTML e-mail as part of the JSP? I silently assumed that you wanted your e-mail to be a separate, easily updateable template. Taglibs would be more efficient though.
- Peter
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Peter,
That is correct
I donot need to Object Serialization, since it is in plain text HTML format.

Originally posted by Peter den Haan:
Tag libraries are well supported, but wouldn't that mean embedding your HTML e-mail as part of the JSP? I silently assumed that you wanted your e-mail to be a separate, easily updateable template. Taglibs would be more efficient though.

That is right.My HTML email would be a part of the JSp, if I use the Taglibs.But since, my primary aim was send information through email, and I didnot know about this solution (I am still not sure how to do it ), I thought saving it and then sending would be a better option.
Thank you for your views.
Regards,
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 27, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving an HTML file generated by the JSP on the Server - Possible?