It's not a secret anymore!*
The moose likes Tomcat and the fly likes Context paths always coming up as Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Context paths always coming up as "The requested resource is not available"" Watch "Context paths always coming up as "The requested resource is not available"" New topic
Author

Context paths always coming up as "The requested resource is not available"

Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

I recently started using Tomcat 6 for some webapps and now I can't seem to configure context paths.

First I put it in server.xml, but that didn't work, and reading on http://tomcat.apache.org/tomcat-6.0-doc/config/context.html, I saw it was not recommended either

Then I tried to define one in the $CATALINA_BASE/conf/[enginename]/[hostname]/ dir. but no luck either!

Does this ring a bell for anyone?



So my server xml for 6 looks like

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<Context path="/test" docBase="C:\apps\docs\test" crossContext="true" />
...
</Host>


and I also tried it with C:\development\servers\apache-tomcat-6.0.30\conf\Catalina\localhost\test.xml
with in it: <Context docBase="C:\apps\docs\test" crossContext="true"></Context>

In Tomcat 5 it still works fine.

Thank you for reading!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

My own (working) context files contain the path="/contextpath" attribute.

For example:


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

In server.xml it has that, but it shouldn't have that when you try to use the
$CATALINA_BASE/conf/[enginename]/[hostname]/[pathname].xml

the pathname is derived from the xml name (minus .xml), so in my example it's already got that set as 'test'
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Just saying.

I have nothing in my server.xml except the empty <host> declaration.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

P.S. The Tomcat Manager app will show you whether the contexts have even been recognized and/or deployed.
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

I appreciate the suggestion. I did try that, to add the path attrib in there as well, but still the same.

I don't know the manager app, will have to see how I can get to that. Thanks!
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

Wow, weird, the /test context shows as running!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

OK, so that means Tomcat has recognized the context as valid and deployed it. That narrows down the problem quite a bit. The next most likely culprit is the URL you are using to hit the app.
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

The manager itself (which runs at http://localhost:8080/manager/html) points to

http://localhost:8080/test/

also tried http://localhost/test/

I've also tried to access files directly that I know are in that directory
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Do you have an index.jsp or index.html at the context root? Or some other welcome file configured? If there's nothing there to serve, you'll get an error (unless you've enabled directory listings).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Hans Otjes wrote:I've also tried to access files directly that I know are in that directory

Give us some details.
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

I was hoping to see a directory listing.
Where would you enable that?

For your second question. In the test folder, there are files like "icon.png"

so I've put that string in the above mentioned urls as well, to make sure it wasn't just a listing issue
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Hans Otjes wrote:I was hoping to see a directory listing. Where would you enable that?

In Tomcat's conf/web.xml file, you'll find the following (in mine it's at line 102):
change the value to true.

For your second question. In the test folder, there are files like "icon.png" so I've put that string in the above mentioned urls as well, to make sure it wasn't just a listing issue

Hmm, so icon.png is in the same folder as WEB-INF, and yet /test/icon.png results in a 404? Anything in the logs?
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

This folder is not really a webapp, just a directory in my filesystem to host some loose files (in my case swf files)

So there is no WEB-INF directory.



Does listings - false mean it's disabled? or enabled?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Listings == false == disabled.

And, oh. Yeah. Create a WEB-INF and a WEB-INF/web.xml. Otherwise, nothing is guaranteed to work.
Hans Otjes
Greenhorn

Joined: Mar 09, 2011
Posts: 9

Didn't work either.
It must be sth else, tomcat 5 didn't require me to do that either....

It's for local testing, so I'll just have my swfs built in the root dir so I can test them there. Not ideal, but I've spent too much time on this.

Thanks for your help & suggestions!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Hans Otjes wrote:This folder is not really a webapp, just a directory in my filesystem to host some loose files (in my case swf files)

So there is no WEB-INF directory.



Does listings - false mean it's disabled? or enabled?


I'll forgo the screaming large type WEB server is NOT FILE server admonition. I already did that once here this week. Bear's advice is accurate.

However, I have recently discovered to my sorrow that if you place context xml file in TOMCAT_HOME/conf/Catalina/localhost, the context name it will be deployed under will be taken from the NAME of the context file, not the context name supplied in the file.


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

Joined: Mar 09, 2011
Posts: 9

I tried the web inf + web.xml suggestion, based it on the webapps/docs sample, but still no success

On it not being a file server, I know that, I just need to have local access to some swf files, loading them from file system has you run in to security limitations.

And again, this was working fine on tomcat 5.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Just so long as you know! Too many people don't, alas.

I know of no changes between Tomcat5 and Tomcat6 that would make a difference. I suggest looking at catalina,out and the localhost log to see if there are any interesting messages in there. Including what context path the webapp was deployed under.

Just for general info, I also recommend using the Unix-style path format over Windows-style (C:/apps/docs/test). Backslashes can bite in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Context paths always coming up as "The requested resource is not available"