0

I want users to access /shared folder on my server through a web-app, hosted on Tomcat in the same server. Following solutions i have tried, but none of them worked.

  1. Putting context entry in the server.xml
    <Context path="/shared" docBase="/shared/" reloadable="true" crossContext="true"/>

  2. Putting the same context information in /conf/context.xml inside Tomcat.

  3. Putting the same context information in /META-INF/context.xml under my webapp.

But when i try to access it using http://{myserverip:portnumber}/shared, it returns with a 404 Error.

Tomcat Version : 7 Server OS: Ubuntu 12.04

Any Suggestions?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Aman Arora
  • 1,232
  • 1
  • 10
  • 26
  • You can write your own "file browser" servlet, or you can yous something already existing, e.g.: http://www.servletsuite.com/servlets/fmanager.htm – Moritz Petersen Jan 09 '14 at 08:02

1 Answers1

2

You need to do 2 things, I will not recommend this solution unless it's some local dev server on which you want to share and list your directories.

Firstly, under /conf/catalina/ you create a shared.xml which has

<Context path="/shared" docBase="/shared/"/>

Secondly (and this bit I dont recommend) you have to enable directory listing under Tomcats' conf/web.xml - look for the DefaultServlet and change listings to true

this affects ALL web apps on your Tomcat server

<servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

for more fine control, you can over ride this in your individual web app Web.xml but from your scenario I'm not sure you have one.

also see How can I list all the files in folder on tomcat?

Community
  • 1
  • 1
JoseK
  • 31,141
  • 14
  • 104
  • 131
  • Thanks for the response. My actual requirement is to "Provide a Url To the user to View Files, But those files shouldn't be accessible by other users". Users on their end will put that url in an applet that will create 3D visualizations of the file hosted on that url. I could not find any solution. – Aman Arora Jan 09 '14 at 08:57
  • I implemented the first solution, but it doesn't work. Second thing i can't do as there is an application hosted on Tomcat. – Aman Arora Jan 09 '14 at 09:03
  • Thats quite different then. You would need the applet to hit the Tomcat URL for a given file (using the full URL, not the directory listing) and a servlet to stream the file at that given URL - with security control. You wont need the directory structure at all really – JoseK Jan 09 '14 at 09:03
  • Yes that's what i need to do. But How can i stream file to a particular Url? It will be nice if you provide a link to start with . Thanks. – Aman Arora Jan 09 '14 at 09:07
  • something like http://stackoverflow.com/questions/4645441/most-effective-way-to-write-file-to-servletoutputstream – JoseK Jan 09 '14 at 09:08
  • I will try this. Thanks so much . And as i have mentioned, the solution which you mentioned still gives `404`. – Aman Arora Jan 09 '14 at 09:10