tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TOMITA_ALEX_NONLI...@LILLY.COM
Subject RE: Quick Question
Date Tue, 13 Aug 2002 14:29:19 GMT
Hi all,

I'm trying to resolve this problem with all the solutions that you gave 
me,  but it doesn't work...
This is what I did:

in my java bean (not a servlet), I have this code:


public class DbBean {
   public  int Connect()  {
   InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("config.txt");
        if (is == null) {
                return 0;
        }
        else {
                return 1;
        }
}


then in my jsp, I called this method, and then I write the value (0 or 
1)..

The txt file is in "WEB-INF/classes/beans...", because "DbBean" is in a 
package called "beans", and I start tomcat from TOMCAT_HOME/bin..
When I load the jsp, the method Connect of the DbBean (java bean) returned 
0, which means the InputStream is null, but if I put the txt file in
TOMCAT_HOME/bin, I had no problem...., the method returned 1....  why is 
that??.. I'm using Tomcat 3.2
Do I need to set something else in Tomcat??....

thanks again
Alex Tomita













"Drinkwater, GJ (Glen)" <G.J.Drinkwater@dl.ac.uk>
13/08/2002 08:11 a.m.
Please respond to Tomcat Users List

 
        To:     Tomcat Users List <tomcat-user@jakarta.apache.org>
        cc: 
        Subject:        RE: Quick Question




tomcats default directory is where ever you called the startup.sh/bat 
file.
So if you dont use another script to call the startup.sh/bat file tomcats
default will be the bin directory.

Use this code to find the directory where WEB-INF is.  Then you can 
traverse
your directory structure from there. 

//get context path
    ServletConfig scon = null ;
    String workingDir = null;
 
    public void init(ServletConfig config) {
        scon = config ;
     }
 public void doPost(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, IOException {
 
        //get working dir
        ServletContext sc = scon.getServletContext();
        workingDir = sc.getRealPath("");


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message