• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just off the top of my head, so it's guaranteed not to work:

Good luck
- Peter
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I havent tried with filtering....but this link has good explanation on Filters.
Anil
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic