Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to show html page

 
Rajan Chinna
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64627
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajan Chinna
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64627
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Cesar Olavo
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic