File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save html output of jsp into a file

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • 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.
 
Ghazanfar Qureshi
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
maha anna
Ranch Hand
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic