wood burning stoves 2.0*
The moose likes Servlets and the fly likes how to expose defined directory under webapps 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 » Java » Servlets
Bookmark "how to expose defined directory under webapps" Watch "how to expose defined directory under webapps" New topic
Author

how to expose defined directory under webapps

John McDonald
Ranch Hand

Joined: Jul 01, 2003
Posts: 112
Hello Guru,
I just installed tomcat. How do I make my hello.html under a directory my_dir visible to the web? Thanks.
tomcat\webapps\ROOT
\my_dir\hello.html
John
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
<tomcat-root>\webapps\yourApp\my_dir\hello.html

The above deployment is better, coz you just don't need to mess up with the default web application of Tomcat in the future development as well...
But your deployment is also alright... What problem are you facing now?


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It looks like the problem you are having is that you're trying to view the file in the ROOT web app, but you are placing the file in a sub-directory. It's been a while since I used Tomcat, but I believe it treats this as a web-context ie a web app different to the one you've specified.
Try placing the file in the tomcat\webapps\ROOT directory and verify that you can load it as localhost/hello.html
To expand on the problem, servlet containers are designed to serve multiple separate 'applications' at the same time, and keeps them separate by giving them a named 'context'. Usually the behaviour is that the first part of the request is the context. Therefore http://localhost/app1/hello.html loads hello.html from the app1 context and http://localhost/app2/hello.html loads hello.html from the app2 context.
Then there is a special context that has no name and is a convenient place to drop your application,s but sometimes nested directories get treated like contexts, and I believe this is the behaviour you are seeing.
As I said, try dropping the file in the root directory and see if it works. Someone with more specific Tomcat knowledge may be able to provide a work-around.
Dave
Jayson Falkner
Author
Ranch Hand

Joined: May 07, 2001
Posts: 57
You have probably already done it. If you put my_dir in the webapps/ROOT directory, you should be able to see hello.html by going to http://127.0.0.1/my_dir/hello.html or if you haven't changed Tomcat's default port, the page would appear on http://127.0.0.1:8080/my_dir/hello.html -- also make sure Tomcat is on!
As was mentioned above, usually you don't want to put things on the web this way. Usually you make a whole "web application" that you have Tomcat map to a URL, e.g. http://www.yourserver.com/foo or http://www.yourserver.com/, etc). There are of course lots of benefits to making your own web application instead of placing directories in webapps/ROOT, but that is something to worry about another day.


Jayson Falkner<br />jayson@jspinsider.com<br />Author of <a href="http://www.jspbook.com" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Jayson Falkner:
There are of course lots of benefits to making your own web application instead of placing directories in webapps/ROOT, but that is something to worry about another day.

That's what I have mentioned before...
Deployment in Tomcat is not that difficult, as we might expect. But sometimes we will mess them up, if we do not carefully maintain the proper structure of Tomcat... Here is the link to the doing basic things with Tomcat by Mr.Kevin... U might want to have a look on it....
http://kevinj.develop.com/javahome/javatomcat.jsp
John McDonald, hope your testing works well....
[ January 27, 2004: Message edited by: Ko Ko Naing ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to expose defined directory under webapps