Make a directory visible to tomcat

P

pd

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.
 
U

udelram

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/
 
L

Lew

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/

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.
 
M

ManojKumar

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.



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.
 
M

ManojKumar

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.



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top