Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Make a directory visible to tomcat

Thread view: 
pd - 30 May 2007 01:21 GMT
guys,

i am using tomcat 5.0. now i need to access a local file using
http://localhost:8080/filename. so i need to make that folder visible
to tomcat and somehow tell it that file location is actually c:\data
\index.htm, so i can access that file through the web URL and not the
file URL.

i think i am meant to edit web.xml, but can somebody please help me
out here. thanks.
udelram@gmail.com - 30 May 2007 03:30 GMT
peted,

I'm using Tomcat 6.0.

Any files I need it to see, I put it in Tomcat 6.0\webapps\ROOT
\<folder name>\<file name>
Not sure what the folder structure in Tomcat5.0 is, but see if you can
find something here http://tomcat.apache.org/tomcat-5.0-doc/index.html

so your path on the local machine would be http://localhost:8080/<foldername>/<filename.html
or filename.jsp>
pd - 30 May 2007 03:49 GMT
cheers mate. thanks.

what if the directory is somewhere completely different, like C:\Data
\Backup\External.

Then how do you point tomcat to this particular folder using
http://localhost:8080/Data/Backup/External

thanks again.
udelram@gmail.com - 30 May 2007 05:14 GMT
I assume you cannot/dont want to put the data in that directory.

You'll have to make changes to the server.xml file

In Tomcat\conf\Server.xml, find this

<Context path=”" docBase=”webapps/ROOT” debug=”0″ reloadable= “true”/>
and change it to this:
<Context path=”/” docBase=”<Your path>” debug=”0″ reloadable=”true”/>
(if that line doesn’t already exist, then just add it)

Offhand, I'm not sure if you need to make changes to the httpd.conf
file, but if that doesnt work, see if this helps

http://www.coreservlets.com/Apache-Tomcat-Tutorial/
Lew - 30 May 2007 14:26 GMT
> I assume you cannot/dont want to put the data in that directory.
>
[quoted text clipped - 11 lines]
>
> http://www.coreservlets.com/Apache-Tomcat-Tutorial/

The OP didn't say they were using Apache Web Server.

It's bad practice to locate resources for a web app outside the web app.  I
would read up carefully on the <Context> tag of server.xml - I seem to recall
some dangers in defining a path="/" but I can't be bothered to google for it
just this moment.  I'm also not convinced that server.xml attributes will do
what you want.

It sounds like you're trying to access server-local resources outside the
Tomcat environment from a specific web app.  The easiest way I think of is to
create a context attribute in the web.xml with the fully-qualified path value
to the resource.  You can retrieve that value from the ServletContext inside
your app.

I recommend that you use forward slashes, even better, define it as a URL:
file://c:/path/to/wherever/file.ext

If you are using Apache Web Server you have better alternatives.  You can
define certain directories on your server to correspond to certain URLs in the
clients in the httpd.conf as udelram suggested.

The approaches are compatible.  You can define the URL of the referred
resource in your web.xml as the location of the resource.

Signature

Lew

ManojKumar - 30 May 2007 17:01 GMT
> udel...@gmail.com wrote:
> > I assume you cannot/dont want to put the data in that directory.
[quoted text clipped - 39 lines]
> --
> Lew

Go to this location "C:\Program Files\Apache Software Foundation
\Tomcat 5.5\conf\Catalina\localhost" . Create an xml file under this
current location. For example you have created "rough.xml" file. Write
"<!-- Test New folder Context --> <Context path="/test/pathways"
docBase="C:\test\pathways" debug="0" reloadable="false"
crossContext="false" swallowOutput="false"> </Context>" in that file
without double quotes. save it. Now create a directory structure like
"C:\test\pathways" and under this create an index html file (it is
default html file) named "index.html". Write whatever you want in this
html file. Open browser. In address bar type "http://localhost:8080/
test/pathways" . The index page will be displayed. That s it.

I dont think u need more explanation. If u r confused, message me.
ManojKumar - 30 May 2007 17:02 GMT
> udel...@gmail.com wrote:
> > I assume you cannot/dont want to put the data in that directory.
[quoted text clipped - 39 lines]
> --
> Lew

Go to this location "C:\Program Files\Apache Software Foundation
\Tomcat 5.5\conf\Catalina\localhost" . Create an xml file under this
current location. For example you have created "rough.xml" file. Write
"<!-- Test New folder Context --> <Context path="/test/pathways"
docBase="C:\test\pathways" debug="0" reloadable="false"
crossContext="false" swallowOutput="false"> </Context>" in that file
without double quotes. save it. Now create a directory structure like
"C:\test\pathways" and under this create an index html file (it is
default html file) named "index.html". Write whatever you want in this
html file. Open browser. In address bar type "http://localhost:8080/
test/pathways" . The index page will be displayed. That s it.

I dont think u need more explanation. If u r confused, message me.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.