0

To be precise I need to get pictures from an external directory say: C:/MWDB. I found this link: How to config Tomcat to serve images from an external folder outside webapps? which I wanna follow up with the part where you need to add a directory in your server.xml context tag.

So Basically Based on the way it says I came with that it should be like:

<Context docBase="C:/MWDB" path="/images" reloadable="true" source="org.eclipse.jst.jee.server:Duck"/> (request: www.example.com/images/image.png) with this way while restaring the server it pops me an error saying

The server at localhost has encountered a problem

Which then I did this: <Context docBase="C:/MWDB" path="/images"/> And This I can't even access my index.html file

FULL server.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Server port="20011" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
  <GlobalNamingResources>
   <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector connectionTimeout="20000" port="20012" protocol="HTTP/1.1" redirectPort="8443"/>
    <Connector port="20013" protocol="AJP/1.3" redirectPort="8443"/>
    <Engine defaultHost="localhost" name="Catalina">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

      <Context docBase="C:/MWDB" path="/images" reloadable="true" source="org.eclipse.jst.jee.server:Duck"/></Host>
    </Engine>
  </Service>
</Server>

I'm using Java 8, Apache Tomcat v9.0

Community
  • 1
  • 1
Mr. Nobody
  • 89
  • 1
  • 9

1 Answers1

0

Okay I figured out my problem.

Basically What I didn't know is that you could have multiple <context> at the same time.

So When I had something like:

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

I could Server from only MWDB directory and not my internal Project and that is why I couldn't access my index.html file. So For to server from both directory Simply you can do:

<Context docBase="C:/MWDB" path="/images" reloadable="true" source="org.eclipse.jst.jee.server:Duck"/>
<Context docBase="C:/MWDB" path="/images"/>

Works Perfectly so far :)

Mr. Nobody
  • 89
  • 1
  • 9