wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Tomcat 7 aliases usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 7 aliases usage" Watch "Tomcat 7 aliases usage" New topic
Author

Tomcat 7 aliases usage

Skanus Meduoliai
Greenhorn

Joined: Oct 24, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 15964
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Skanus Meduoliai
Greenhorn

Joined: Oct 24, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 15964
    
  19

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

Joined: Oct 24, 2012
Posts: 3
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

Joined: Jun 25, 2001
Posts: 15964
    
  19

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).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tomcat 7 aliases usage
 
Similar Threads
Tomcat service terminated unexpectedly (Tomcat5.0.28, apache2.0.54 and mod_jk 1.2.5)
problem in context root
Context Attribute Replication in Tomcat 6
Help: upgraded from tomcat 5.0 to 5.5.27 and getting Naming Exception
Problem in viewing uploaded images