You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Matthias Hupp <mh...@gmx.de> on 2001/04/23 02:44:33 UTC

Accessing HTML files in the apache root from servlets

Greetings everyone,
I am going mad over this: I have a servlet directory structure in my apache
virtual host document root. Servlets can be reached by typing
"www.../servlet/ServletName. I am trying to access a html file from that
servlet as input data, it could be  just any type of text file. Its name is
passed to the servlet in the URL:
www.../servlet/ServletName?search=inputfile.html. I would like to place that
file somewhere in the apache document root, ideally in the same directory as
the classes.
But tomcat (or the JRE from the Sun JDK, not sure) looks for that file in
the server system root if I do not specify the correct (system) path  -
/usr/local/... - in the URL. First, this path is very very long, and second,
users shouldn't be bothered with the directory structure of my system (it is
really ugly).
BTW, the software versions of the tomcat engine and the JDK are, AFAIR, the
latest respective releases.
So, could anybody tell me how to tell tomcat (or the JRE) to consider the
web-documents directory as their root? Any help is greatly appreciated.

Thx in advance, Matthias


Re: Accessing HTML files in the apache root from servlets

Posted by Matthias Hupp <mh...@gmx.de>.
Thanks for the replies so far, but my problem remains...
Is looking for input files in the system root really normal behaviour for a
java program? Has anybody else had my problem?
BTW, using ./inputfile.html doesn't work either.

Greetings, Matthias


RE: Accessing HTML files in the apache root from servlets

Posted by Craig O'Brien <cr...@dynamic-apps.com>.
If you are ever in doubt, use the complete path to your html file.
(http://www.yourdomain/yourpage.html)  That should always work.  Otherwise
you may have a mapping problem with your mod_jk or ..?  You can access your
graphics like this as well, ... Hell, even put your graphics on a different
server for better performance.....

If your directory is a mess you are only looking for trouble.  It WILL get
worse over time.

Regards,
Craig

-----Original Message-----
From: Iain Lowe [mailto:ilowe@videotron.ca]
Sent: Sunday, April 22, 2001 5:52 PM
To: tomcat-user@jakarta.apache.org
Subject: RE: Accessing HTML files in the apache root from servlets


You could try

FileReader in = new
FileReader(this.getServletContext().getRealPath("/inputfile.html"))

or something along those lines.

Hope this helps :)

-----Original Message-----
From: Matthias Hupp [mailto:mhupp@gmx.de]
Sent: Sunday, April 22, 2001 8:45 PM
To: tomcat-user@jakarta.apache.org
Subject: Accessing HTML files in the apache root from servlets


Greetings everyone,
I am going mad over this: I have a servlet directory structure in my apache
virtual host document root. Servlets can be reached by typing
"www.../servlet/ServletName. I am trying to access a html file from that
servlet as input data, it could be  just any type of text file. Its name is
passed to the servlet in the URL:
www.../servlet/ServletName?search=inputfile.html. I would like to place that
file somewhere in the apache document root, ideally in the same directory as
the classes.
But tomcat (or the JRE from the Sun JDK, not sure) looks for that file in
the server system root if I do not specify the correct (system) path  -
/usr/local/... - in the URL. First, this path is very very long, and second,
users shouldn't be bothered with the directory structure of my system (it is
really ugly).
BTW, the software versions of the tomcat engine and the JDK are, AFAIR, the
latest respective releases.
So, could anybody tell me how to tell tomcat (or the JRE) to consider the
web-documents directory as their root? Any help is greatly appreciated.

Thx in advance, Matthias



RE: Accessing HTML files in the apache root from servlets

Posted by Iain Lowe <il...@videotron.ca>.
You could try

FileReader in = new
FileReader(this.getServletContext().getRealPath("/inputfile.html"))

or something along those lines.

Hope this helps :)

-----Original Message-----
From: Matthias Hupp [mailto:mhupp@gmx.de]
Sent: Sunday, April 22, 2001 8:45 PM
To: tomcat-user@jakarta.apache.org
Subject: Accessing HTML files in the apache root from servlets


Greetings everyone,
I am going mad over this: I have a servlet directory structure in my apache
virtual host document root. Servlets can be reached by typing
"www.../servlet/ServletName. I am trying to access a html file from that
servlet as input data, it could be  just any type of text file. Its name is
passed to the servlet in the URL:
www.../servlet/ServletName?search=inputfile.html. I would like to place that
file somewhere in the apache document root, ideally in the same directory as
the classes.
But tomcat (or the JRE from the Sun JDK, not sure) looks for that file in
the server system root if I do not specify the correct (system) path  -
/usr/local/... - in the URL. First, this path is very very long, and second,
users shouldn't be bothered with the directory structure of my system (it is
really ugly).
BTW, the software versions of the tomcat engine and the JDK are, AFAIR, the
latest respective releases.
So, could anybody tell me how to tell tomcat (or the JRE) to consider the
web-documents directory as their root? Any help is greatly appreciated.

Thx in advance, Matthias