简体   繁体   English

servlet上下文到tomcat 7 root

[英]servlet context to tomcat 7 root

Whats the best approach to place servlet context to tomcat 7 root? 什么是将servlet上下文放置到tomcat 7 root的最佳方法? I have tried this post here but didn't work for me; 在这里试过这篇文章,但对我不起作用; i'm using Apache Tomcat/7.0.42 . 我正在使用Apache Tomcat/7.0.42

PS: I don't want to rename the project name as ROOT.war . PS:我不想将项目名称重命名为ROOT.war

Update 更新

I have placed the context tag as explained in one of the answers, but still getting the tomcat home page as root: 我已经按照其中一个答案中的说明放置了context标记,但仍然以root身份获取tomcat主页:

<Host name="localhost"  appBase="webapps"               
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
         prefix="localhost_access_log." suffix=".txt"
         pattern="%h %l %u %t &quot;%r&quot; %s %b" />    
   <Context docBase="app-renderer" path="/" reloadable="true" />
 </Host>

Update 2 更新2

the problem was about the ROOT directory in webapps , after removing now I could have the app as root. 问题是关于webappsROOT目录,现在删除后我可以将应用程序作为root用户。

In your Tomcat's conf/server.xml file, you'll typically have an entry 在Tomcat的conf/server.xml文件中,您通常会有一个条目

<Context docBase="yourApp" path="/somePath" reloadable="true" source="someSource"/>

for your application. 为您的应用程序。

Change the path to / 将路径更改为/

<Context docBase="yourApp" path="/" reloadable="true" source="someSource"/>

Add this in the Host entry. Host条目中添加它。 For example 例如

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
<Context docBase="yourApp" path="/" reloadable="true" />
</Host>

where the docBase attribute is the name of your app as it appears in the webapps folder. 其中docBase属性是应用程序的名称,因为它显示在webapps文件夹中。 The docs explain the meaning of each attribute. 文档解释了每个属性的含义。

check the context documentation . 检查上下文文档 You're looking for the docBase attribute for your webapp's path and the path attribute for the root context, eg leave it empty as described in the attribute's documentation. 您正在寻找webapp路径的docBase属性和根上下文的path属性,例如,如属性文档中所述,将其保留为空。

Without changing the .war file to ROOT follow below steps: 无需将.war文件更改为ROOT按照以下步骤操作:

1. Create a file named ROOT.xml under the tomcat/conf/Catalina/localhost/ 1.tomcat/conf/Catalina/localhost/下创建一个名为ROOT.xml的文件

2. paste below code into the ROOT.xml file: 2.下面的代码粘贴到ROOT.xml文件中:

<Context
  docBase="/home/user/YOUR_PROJECT/target/YOUR_PROJECT.war"
  path=""
  reloadable="true"
/>

Now you can access your project in tomcat root. 现在您可以在tomcat root中访问您的项目。

To have a clean project remove tomcat/webapps/ROOT directory. 要有一个干净的项目删除tomcat/webapps/ROOT目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM