• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Giving path alias to network folder in server.xml

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am using tomcat 6.0, I need to read some image files from a network directory.
I have context path setup as
<Context path="/pictures" docBase="\\server\pictures" />
but when i try to read these images using "/pictures/image.jpg" its not coming up on the UI
I tried to access that folder by typing urlpath to that image in IE that also is giving resource not found error..
I am able to access that network drive from the windows explorer directly just not through my app

How can I configure a path to network drive?

thanks


 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it work if you set docBase to your local drive?
 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried
<Context path="/pictures" docBase="C:/pictures" />
then
http://localhost:8080/pictures

that also didnt work
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jasdeep parmar wrote:that also didnt work



What do you mean by didn't work?

Should be ?

Have you tried to access individual pictures?
 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was getting resource not found error when typing the url below in IE
http://localhost:8080/pictures/image1.jpg


but with backslash
"C:\pictures"
http://localhost:8080/pictures/image1.jpg -- i get the picture


i am able to access local drive but still can't read images on network drive..
I am setting it as below
<Context path="/pictures" docBase="\\server\pictures" />

I am able to access the pictures directly if i type \\server\pictures in windows explorer

thanks


thanks
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is only going to work if the browser and the Tomcat server are on the same physical machine. That's because your URLs point to places on the client machine and not to places on the server.

If you want Tomcat to serve out images which aren't within the web application then the way to do that is via a servlet which gets the image from its actual location and copies it to the response's output. Google keywords: "image servlet".
 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what i am trying to figure out how to set up the actual location which is on the network server..

thanks
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to make sure there isn't any confusion, I hope you're aware that "docBase" is the location of the application WAR, and not just "documents"! And from my experience, putting a WAR on a network drive makes it execute unreliably, if at all.

Let me drag out the old mantra:


A web server is not a file server.



As Paul mentioned, the only way to get "files" from outside the WAR is to have a servlet that will open the file localy on the web application server (which CANNOT read files on the client), then have that application copy the contents of the file to the HTTP output stream that the web server is returning to the client. You can't simply direct the client to access the file directly, since


A web server is not a file server.



Avoid using backslashes in file path names in Java. Backslashes come with side effects. Even in Windows, it's safer to say 'docBase="C:/webapps/pictureApp" than to use backslashes.

My other mantra is:


A URL path is not a file path.



URLs are directives to the web server used to route requests to specific webapps. The webapps then dissect the URLs to determine what action to take. The confusion comes from the fact that by default, the action taken is to remove the server and context parts of the URL and use the remaining path part of the URL as a resource path within the docBase.

So for a WAR located in "C:/webapps/dirtypictures" the way to retrieve the image in the "images/hotbabe21/jpg" file if your Context looks like this:



The URL would be "http://servername:8080/familypictures/images/hotbabe21.jpg" and not "http://servername:8080/dirtypictures/images/hotbabe21.jpg"

Because this image is located within the WAR itself, no specialized configuration or copy-to-client logic is required, as the default URL action is being done automatically by the Tomcat server. If your actual images directory was located on a network drive accessible to the web server, a copy-to-client servlet would be required.>
 
jasdeep parmar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My applications war in not on the network drive.
It is on the local machine where tomcat itself is.
The images i need to get are in "pictures" folder on network drive


To check if the file exist i am using this
String url = webUrl +"/pictures/image1.jpg";
HttpURLConnection co n = (HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
boolean exist = (con.getResponseCode() == HttpURLConnection.HTTP_OK);

LogHelper.log("respose " + con.getResponseCode());
this also return code 404;

so even if I use servlet how do i give it a path as to where to go..

thanks


 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't make sense. What you wrote makes it look like the pictures are coming from another web server, not a network drive (file server).

You sounded more like you wanted something like this:



Where "N" is a network mapped drive. You may need to modify pictureFileName to remove bits of URL that you don't want.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jasdeep parmar wrote:My applications war in not on the network drive.
It is on the local machine where tomcat itself is.
The images i need to get are in "pictures" folder on network drive


To check if the file exist i am using this
String url = webUrl +"/pictures/image1.jpg";
HttpURLConnection co n = (HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
boolean exist = (con.getResponseCode() == HttpURLConnection.HTTP_OK);

LogHelper.log("respose " + con.getResponseCode());
this also return code 404;

so even if I use servlet how do i give it a path as to where to go..



You have to have something which maps URLs of the form "/pictures/*.jpg" to a servlet, rather than just allowing it to do its normal thing of returning an image. Then that servlet would look at the URL and find the actual image in the local directory where they are stored, and return ig.
 
Greenhorn
Posts: 28
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i guess Image alias is a feature of Tomcat 7 not tomcat 6.. try doing the same in Tomcat 7.. it works for me
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic