× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



> Joe,
>
> Tomcat 4.0 follows the Servlet 2.3 and JSP 1.2 specifications
> exactly and is the reference implementation. That is why you
> won't find any "extensions". To specify a directory outside of
> your webapps directory, you need to set up a context in your
> server.xml file that is not relative like:
>
> <Context path="myapp" docBase="/myapp" debug="0" />
>
> The docBase does what you need. In this case a url like:

David, this is actually a different issue.  I'm not worried about trying to
redirect my document base; that is already done.  The documents come from
within the Tomcat folder as needed.  In my server.xml, I have the following:

        <!-- Tomcat Root Context -->
        <Context path="" docBase="ROOT" debug="0"/>

This gets all my JSP, HTML and so on served from folders under ROOT.  I'm
pretty sure this is the default, also, but I decided to explicitly identify
it.

The problem arises when I attempt to do something like this in my servlet:

File file = new File("myprops.ini");

I am trying to open a .ini file.  In this case, standard Tomcat points me
back to the root of the IFS.  Now, on both WebSphere and on the Apache
version of Tomcat I can specify the root for File objects by using the
"ServerRoot" directive, but there is no equivalent in Tomcat standalone.

Try this in a servlet:

        String[] files = { "file", "/slashfile", "./dotfile", "/./slashdotfile" 
};

        out.println("<H4>File paths</H4>");

        out.println("<table border=4>");
        out.println("
<tr><th>AbsoluteFile</th><th>AbsolutePath</th><th>CanonicalFile</th><th>Cano
nicalPath</th></tr>");

        try {
                for (int i = 0; i < files.length; i++)
                {
                        File file = new File(files[i]);
                        out.println("  <tr><td>" +
                                file.getAbsoluteFile() + "</td><td>" +
                                file.getAbsolutePath() + "</td><td>" +
                                file.getCanonicalFile() + "</td><td>" +
                                file.getCanonicalPath() + "</td></tr>");
                }
        } catch (Exception e1) {}

        out.println("</table>");

This code will print out the results of the absolute and canonical files and
paths for files with various types of addressing.  When you run this under
WebSphere and under Apache/Tomcat, the two relative files ("file" and
"./dotfile") give values with the ServerRoot prepended, such as
"/www/apachetest/file"), while with Tomcat standalone, they start at the
root of the IFS ("/file"), regardless of the docBase.

Because of this, I would have to hardcode in the entire absolute path to
Tomcat in order to access my .ini file, which makes it very difficult to set
up multiple instances with different properties.

I hope this makes sense.  It's a crucial issue when trying to set up
configuration files.

Joe



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.