aspose file tools*
The moose likes Servlets and the fly likes How to save html output of jsp into a file 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 "How to save html output of jsp into a file" Watch "How to save html output of jsp into a file" New topic
Author

How to save html output of jsp into a file

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 15, 2000
Posts: 20
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 15, 2000
Posts: 20
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

Joined: Jan 31, 2000
Posts: 1467
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
 
subject: How to save html output of jsp into a file