Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

tomcat - How to set my webapp to appear as ROOTfor localhost:8080

I've got a webapp in my Tomcat/webapps directory. My app's directory is "site" and is showing as http:localhost:8080/site

I'd like to have the site show as http://localhost:8080/

I've read the docs and tried creating a ROOT.xml file in my Tomcat/conf/Catalina/localhost directory to create a ROOT context path but the connection isn't being made.

Can someone nudge me in the right direction? Here's the content of that ROOT.xml file.

<Context  docBase="site" path="/"> </Context>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The easiest approach to getting root context would be to simply rename your app's directory from webapps/site to webapps/ROOT and restart Tomcat. If there's already a ROOT app in your default webapps folder, then you need to create another Host, because there may be only one root context app per Host.

Another option (again, if you don't already have a ROOT app under webapps) would be to edit your conf/server.xml file and add your context element within the default <Host>:

<Context path="" docBase="site" />

If you'd like to create a separate host, then you'll need to define a second <Host> in server.xml, e.g.,

<Host name="anotherhost" appBase="webapps_anotherhost"></Host>

For the above to work, you'd need to create a webapps_anotherhost folder as a sibling folder next to your default host's webapps folder, and then drop your WAR in that folder, either as an exploded directory named ROOT or a compressed WAR named ROOT.war. Then restart Tomcat and browse your application at http://anotherhost:8080 (you'll also a hosts file entry, of course).

These are just a few of the many options. The Tomcat docs are fairly detailed about this stuff. You can find the docs for your version of Tomcat at http://tomcat.apache.org/.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...