| Author |
error when displaying text values on webpage
|
David McHugh
Greenhorn
Joined: Oct 01, 2008
Posts: 23
|
|
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
Joined: Jan 10, 2002
Posts: 56191
|
|
What does a View Source show? P.S. Your code is hard to read because of the poor indentation. I'd attend to that,
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
David McHugh
Greenhorn
Joined: Oct 01, 2008
Posts: 23
|
|
hi bear, it shows nothing, no html just a blank document. cheers
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Udayaditya Barua
Greenhorn
Joined: Dec 05, 2008
Posts: 8
|
|
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
Joined: Nov 20, 2008
Posts: 254
|
|
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 ]
|
“Everything should be as simple as it is, but not simpler.” Albert Einstein
|
 |
David McHugh
Greenhorn
Joined: Oct 01, 2008
Posts: 23
|
|
|
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!!!
|
 |
 |
|
|
subject: error when displaying text values on webpage
|
|
|