• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Tomcat 7 aliases usage

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I would like to share some static images outside of web application WAR file. I found that Tomcat 7 have new functionality that allows to do that easily using new aliases system.

But for me it's not so easy to get it working as described in this site.

I am using Ubuntu 12.10 and Tomcat 7.0.32 version.

My uploaded images are stored like this:


In Tomcat configuration I have two context files: admin.xml and uploads.xml each of them looks like this:

admin.xml:


uploads.xml:


Application starts but images is not accessible. I try to access them like this:


Anybody knows how to properly use this aliases? Please?
 
Saloon Keeper
Posts: 24500
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked to see that Tomcat has read access rights to this directory?

Also, the docs say docBase has to point to a .war file or a directory. I'm not sure in the case of "directory" if they're being sloppy and mean that it, too has to be in WAR format.
 
Skanus Meduoliai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It have read access right to this directory. I have tried to make this directory WAR style by adding WEB-INF folder with web.xml file, but images were not reachable.

I found another way of getting access to static images outside web application.

You need define context in server.xml inside Tomcat configuration:

server.xml (this have to go into 'Host' tag):


That way I am able to reach static images like that:


My new question would be:
This way to share static resources is safe? Does it have any disadvantages?
 
Tim Holloway
Saloon Keeper
Posts: 24500
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not define the Context in server.xml. That is a practice that has been discouraged since at least Tomcat4. Put it in a file named "admin.xml" in the TOMCAT_HOME/conf/Catalina/localhost directory.
 
Skanus Meduoliai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was unable to do so, because admin.xml already contains <Context /> tag that points to web application. But I have created another context file images.xml and IT WORKED . Thanks

As I understand this is safe way to share static resources like that?
 
Tim Holloway
Saloon Keeper
Posts: 24500
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not actually "sharing static images". Web servers are not file servers. What you are really doing is creating a third webapp whose sole purpose is to serve up the images.

It is 100% safe/legal/valid for a webpage coming from one webapp to contain URLs (links and images) that are served by other apps - even other servers in other domains. It's what keeps doubleclick.net in business (among many others).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic