Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error when displaying text values on webpage

 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have the following code that compiles ok but does not display anything on the web page when run through the web server, not even the htmml tags, it is just blank, any ideas??

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64969
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does a View Source show?

P.S. Your code is hard to read because of the poor indentation. I'd attend to that,
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi bear,

it shows nothing, no html just a blank document.

cheers
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Two things to try:
1) Output the html skeleton (html/head/body) outside the loop. You need it anyway and that will help tell if the problem lies in the loop.
2) Add flush and close for print writer to ensure all the output makes it out.
 
Udayaditya Barua
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David McHugh:
[QB

[/QB]


Correct me if i m wrong, if this is a windows system, filename path should have backslashes instead of forward.So
String filename = "C:\Java\jakarta-tomcat-5.0.28\webapps\text.txt";
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is here:
Originally posted by David McHugh:

String filename = "C:/Java/jakarta-tomcat-5.0.28/webapps/text.txt";
ServletContext context = getServletContext();

InputStream inp = context.getResourceAsStream(filename);
if (inp != null) {
...
}
}
[/CODE]

Your return input stream is null, hence it didn't write anything to the response, hence the blank response.

The method .getResourceAsStream() of ServletContext should only use relative path to a physical resource inside the web application. If you use it for the real file system path, it will return null. To use the real file system path, you should use java.io package.
[ December 08, 2008: Message edited by: Duc Vo ]
 
David McHugh
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cheers for the replies guys, i changed the path to a relative one and it works ok now. i also used context.getRealPath, thanks again, it is a bit scary when you do not get an error just white on white!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic