File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 7 aliases usage

 
Skanus Meduoliai
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
38
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17616
38
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17616
38
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic