Mapping a directory outside the web-app to URL in TOMCAT

后端 未结 3 800
难免孤独
难免孤独 2020-12-08 00:53

I need to map an directory containing images which resides outside tomcat webapps folder, so that application can serve those images.

I am making a J2EE Web applicat

相关标签:
3条回答
  • 2020-12-08 01:32

    I had the same issue but found a solution.

    If you are using Eclipse and a Tomcat plugin then please note that the Eclipse Tomcat plugin creates a separate CATALINA_BASE under the Eclipse workspace directory.

    You can go to this location and you will find server.xml. Use that server.xml and it will work.

    My actual tomcat directory is:

    C:\apache-tomcat-7.0.62x64\apache-tomcat-7.0.62\conf
    

    and my Eclipse Tomcat server uses:

    C:\workspace\JSF\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf 
    

    Use the workspace path and server.xml from this location.

    Add this in server.xml inside the host tag:

    < Context docBase="D:/personal"  path="/images" />
    

    and it will work if D:/personal has 1.png, and then the url http://localhost:8080/images/1.png will load the image.

    0 讨论(0)
  • 2020-12-08 01:34

    in Tomcat8 you can also add PotsResources to you META-INF/context.xml as follow :

    <Context>
        <Resources allowLinking="false">
            <PostResources readOnly="false"
                           className="org.apache.catalina.webresources.DirResourceSet"
                           base="path-to-your-local-folder"
                           webAppMount="/images"/>
        </Resources>
    
        ...
    </Context>
    
    0 讨论(0)
  • 2020-12-08 01:49

    Add a <Context> tag in server.xml, inside the <Host> tag:

    <Context path="/images" docBase="C:/test/images/" />
    

    Docs will be accessible at http://localhost:8080/images

    0 讨论(0)
提交回复
热议问题