aspose file tools*
The moose likes JSP and the fly likes how to show html page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to show html page" Watch "how to show html page" New topic
Author

how to show html page

Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
How do i show the html page which is out of web context?
If i have a test.html in c: drive, how do i display it?
The following link is not working.

I have a link
<a href="file:///c:/test.html">click here</a>


Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Of course that's not going to work except on the machine on which the file is located.

Either move the file to where the web server can find it, or write a servlet to stream the file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
the file is located on the same machine, still it doesn't work.

I use the following stream method in the jsp, but it is not displaying the html properly.
--------------------------
response.setContentType("text/html");
File file = new File("c:/test.html");
FileInputStream in = new FileInputStream(file);
OutputStream os=response.getOutputStream();
byte[] buf = new byte[4096];
int count = 0;
while ((count = in.read(buf)) >= 0)
{
os.write(buf, 0, count);
}
os.flush();
in.close();
os.close();
--------------------------
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

but it is not displaying the html properly.


That doesn't give us very much to go on.

I would also highly highly and did I mention, HIGHLY, recommend that you do this in a servlet rather than a JSP.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Rajan Chinna:
the file is located on the same machine, still it doesn't work.


I think what Bear meant was that the file would need to be on the same machine as the browser which, of course would be absurd.

What errors are you getting while trying to stream the file from your servlet?
[ May 10, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Cesar Olavo
Greenhorn

Joined: Nov 19, 2004
Posts: 17
hi,

Not seeing any reason why this stream example wouldn't work, I implemented it verbatim and, believe me, it worked both in the localhost and in a remote host. So, unless your html page is faulty (did you try to see it direct from the filesystem?) it should work for you too.

Cesar
Rajan Chinna
Ranch Hand

Joined: Jul 01, 2004
Posts: 320
Using the above code i can stream any ordinary html, but my html is generated from jasperreports. I got to set some parameter before it generate the report, this is to align the content properly.

Anyway Thanks for the info guys. I solve this issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to show html page