aspose file tools*
The moose likes Servlets and the fly likes WHY Doesnt this work in Tomcat and it does in Resin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "WHY Doesnt this work in Tomcat and it does in Resin" Watch "WHY Doesnt this work in Tomcat and it does in Resin" New topic
Author

WHY Doesnt this work in Tomcat and it does in Resin

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Im moving my design site to a tomcat driven site. I have used this exact code a thousand times on Resin enabled servers and even on my local machine but tomcat ignores it. This is the text portion of my page and they are read from .txt files......everything else works just ducky except no text! I even tryed this on one of my other sites that runs resin and its flawless.....What the heck!!! Here is the code:
ServletContext sc = getServletContext();
InputStream is = sc.getResourceAsStream("/sitePages/"+pageName+".txt");
if (is != null){
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = br.readLine()) != null){
out.println(s);
}
br.close();
is.close();
}
Any help would be much appreciated!!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

Try:

It might illuminate you


Customer surveys are for companies who didn't pay proper attention to begin with.
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
Try this (tested on Tomcat, but not Resin):

I, too, have been just starting to work with Tomcat (comes with Forte 3.0 Enterprise) after having worked with a simple syntax-highlighting editor and Resin, and I can say that Resin seems to be much easier to work with. Despite everyone raving about Tomcat, I'm much more impressed with Resin at this point, and I especially recommend it to anyone who's just starting to learn J2EE servlets/jsps. www.caucho.com
Let me know if the above


CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Well kids neither of these really helped. On the first reply with the foo.getAbsolutePath() I got /sitePages/home.txt. The second response wont even compile as DataInputStream in = new DataInputStream(buffer); is deprecated. Im tinkering with it now to see what I can come up with...
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Well Im justabout as frustarted as ive ever been in my life with this. Tomcat my &*(*$%..... I even tryed this code which gives me the absolute path and STILL the InputStream object is coming back as null! What the heck! Here's what i tried:

ServletContext sc = getServletContext();
String path = sc.getRealPath("/sitePages/"+pageName+".txt");
out.println(path);
InputStream is = sc.getResourceAsStream(path);
if (is != null){
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = br.readLine()) != null){
out.println(s);
}
br.close();
is.close();
}
On the out.println(path) Im getting the path to the file (which ended up on the root of my server partition NOT in the web-inf/classes/sitePages folder like Resin returns) So I moved the folder and articles to where the path lead me....Still nothing. I also printed to the page the is object and it is returning null!..I just don't get this. Ive been doing this for months now on another site and have NEVER had a problem with it!
Gerry Giese
Ranch Hand

Joined: Aug 02, 2001
Posts: 247
The following works on both Tomcat 3.2 server (came built-in to Forte for Java Enterprise 3.0) and Resin 2.0x, using JDK 1.3.1_01. Here's my file layout:
<doc-app-root>\
<doc-app-root>\sitePages\foo.txt
<doc-app-root>\WEB-INF\classes\FileTester.class
I suggest that you use relative paths and stay away from using getRealPath(). The code includes two methods to get the input stream. This code compiles without deprecation warnings, and executes flawlessly. If it doesn't work on yours, then I suggest either re-installing Tomcat (pick a version marked 'stable') or forgetting Tomcat altogether and going back to Resin.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Thanks all I got it working using a URL and then getting the context. Sorry I didnt write back sooner.......been real busy
 
Don't get me started about those stupid light bulbs.
 
subject: WHY Doesnt this work in Tomcat and it does in Resin