Tomcat - making a project folder the web root

2020-02-04 06:10发布

I have this folder under Tomcat webapps/mysite which is where all my JSPs and other things are located. To access this folder I go to http://blah.com/mysite and it works just fine. However (because of stylesheets and images statically connected to the root /) I have to make it so that when I go to http://blah.com/ it will load the stuff inside webapps/mysite.

I've tried many different things including contexts and setting the absolute path in server.xml... nothing seems to work, whenever I go to http://blah.com/ it still tries to load the ROOT folder... what's happening here?

标签: java jsp tomcat
4条回答
你好瞎i
2楼-- · 2020-02-04 06:28

You can rename your war from something.war == to ==> ROOT.war.
So, tomcat will unpack the war and will create the folder ROOT for it.
It is a trick that is working on tomcat 8 also.

查看更多
Luminary・发光体
3楼-- · 2020-02-04 06:41

There are a number of ways to make an application the root application. The simplest way is to just replace the contents of webapps/ROOT with the contents of your web application.

For other solutions, please see the following website: http://wiki.apache.org/tomcat/HowTo#How_do_I_make_my_web_application_be_the_Tomcat_default_application_.3F

查看更多
走好不送
4楼-- · 2020-02-04 06:43

The solution I use is to set this in your Tomcat server.xml

Add a <Context> element within the <Host> like below which sets your mysite as the default web app. Note the empty path="" which makes it the default.

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

Attributes of Context Container from the Tomcat docs:

docBase You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.

path All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts.

See others who have had similar question and the similar answer here, here and here

See also Apache Tomcat Configuration Reference - Context

查看更多
叼着烟拽天下
5楼-- · 2020-02-04 06:50

https://stackoverflow.com/users/1123501/george-siggouroglou 's awnser works but lacks a step.

  • delete ROOT and all items
  • copy the war to webapps as ROOT.war

Without the deletion, it may not work. Tested with docker.

查看更多
登录 后发表回答