-1

I am not so into Tomcat configuration and I have the following doubts:

The server.xml configuration file of my Tomcat 7 contains this section:

 <Host name="localhost"  appBase="webapps"
        unpackWARs="true"
        autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">


    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

    <Context path="/my-project/images/" docBase="/data/myproject/cache/images/" />
  </Host>

My main doubt is related to this last line:

<Context path="/my-project/images/" docBase="/data/myproject/cache/images/" />

/data/myproject/cache/images/ contains some other folder containing images used by my Java EE project.

So what exactly means this line?

I think that it means that it maps the /my-project/images/ folder to the external folder (external to the project) /data/myproject/cache/images/

Is this reasoning correct?

My problem is that my application starts but these images are not shown.

So the exact situation is the following one: these images are not stored directly into the /data/myproject/cache/images/ external folder but are putted in subdirectoy of this folder, something like this:

**/data/myproject/cache/images/subdir1/1.png**
**/data/myproject/cache/images/subdir1/2.png**
**/data/myproject/cache/images/subdir1/3.png**

**/data/myproject/cache/images/subdir2/4.png**
**/data/myproject/cache/images/subdir2/5.png**
**/data/myproject/cache/images/subdir2/6.png**

So I think that maybe I have to change this line:

<Context path="/my-project/images/" docBase="/data/myproject/cache/images/" />

in such a way that if is call something like /my-project/images/subdir1 it is mapped to /data/myproject/cache/images/subdir1/

If it could be my problem (I am absolutly not sure of it), how can I specify this particular behavior?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

1

path is the access url of the resource in your project, the docBase is the real path of the folder

<Context path="/my-project/images/" docBase="/data/myproject/cache/images/" />

if your images is in here : "/data/myproject/cache/images/subdir1" and you want to access these images by url in browser. try this
1. find the folder in your tomcat.

conf/Catalina/localhost

2. create a file

*.xml

3. add these code in it

<?xml version="1.0" encoding="UTF-8" ?> 
<Context docBase="/data/myproject/cache/images/subdir1" path="/subdir1" debug="0" reloadable="true" />

4. save the image path like this :

http://localhost:8080/subdir1/1.png

5. restart your tomcat server to enable and load the "*.xml" you have edited. Try the url in step 4. Can you see the image ? if not, tell me what kind of error do you get. I'll help you figure it out.