• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to save html output of jsp into a file

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello EveryBody..
I am using javamail to send an e-mail with attachment.
This attachment is an html which is the output of jsp.
So can anyone tell me how to get/save the html output of
jsp in a file.I am using Tomcat-apache server.
I tried with java.net package using sockets to connect to jsp,and downloading the output to a file.But it works partially..
ie.it can not download from inner directories of server where I used to store jsps..
So tell me the way how to save html output of jsp into a file.
Thanks

Jitu Sonawane.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have u used URLConnection in java.net.* package e.g
URL myUrl= new URL("http://www.xyz.com/dir1/file.jsp");
URLConnection myUrlConnection = myUrl.openConnection();
then u can get hold of input stream of this connection by
InputStream muInput = myUrlConnection.getInputStream();
once u ve input stream u can wrap it in higher level streams like BufferReader and retrive HTML
if u ve tried this then inform me if u achieve it some other way
regards
Ghazanfar Qureshi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ..
But..
I have already tried this problem using URLConnection..But..
It allows me to go upto index.html of our server..but not inside that..like..
"Http://some.com/dir1/xyz.jsp"
It does not go beyond "Http://some.com/"
gives contentlength zero..but it has some output in html..
 
Ghazanfar Qureshi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i ve used this to even retrieve a js file regarding news from moreover site having querystring parameters
http://p.moreover.com/cgi-local/page?query=Pakistan&n=5&o=js
code sample
===========
URL hp;
URLConnection hpCon;
String url="http://p.moreover.com/cgi-local/page?query=Pakistan&n=5&o=js";
StringBuffer contHTML=new StringBuffer(); //to hold the contents of html file
String readLine="";
hp= new URL(url);
hpCon=hp.openConnection();
len=hpCon.getContentLength();
if (len>0){
BufferedReader br=new BufferedReader(new InputStreamReader(hpCon.getInputStream()));
while ((readLine=br.readLine()) != null) {
contHTML.append(readLine);
}
}
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sonawane,
I just expanded Ghazanfar's code and tested. Able to read the output from deep inside http:..../..../servlet/TestServlet for my case. Try to check with this code.
regds
maha anna
 
reply
    Bookmark Topic Watch Topic
  • New Topic