简体   繁体   English

Tomcat如何找到我的Web应用程序的主页?

[英]How does Tomcat find the HOME PAGE of my Web App?

I am just getting started to learn about Web Apps and deploying them to Tomcat. 我刚刚开始学习有关Web Apps并将其部署到Tomcat的知识。 So I started with a sample web app project - made up of struts, hibernate, etc., etc. 因此,我从一个示例Web应用程序项目开始-由struts,hibernate等组成。

The ANT build was successful. ANT构建成功。 Also, was able to deploy the web app through an xml under Catalina/host. 此外,还能够通过Catalina / host下的xml部署Web应用程序。 I am able to open the web site with no issues. 我可以正常打开网站。

This is the structure of my web app 这是我的网络应用程序的结构

 -exploded -WEB-INF -classes -lib -web.xml -index.jsp -welcome.html 

My question is 我的问题是

How does Tomcat know which is the first page / starting page / home page that it is supposed to open? Tomcat如何知道应该打开的第一页/起始页/主页? Which file is this specified in? 此文件指定在哪个文件中?

In any web application, there will be a web.xml in the WEB-INF/ folder. 在任何Web应用程序中, WEB-INF/文件夹中都会有一个web.xml

If you dont have one in your web app, as it seems to be the case in your folder structure, the default Tomcat web.xml is under TOMCAT_HOME/conf/web.xml 如果您的Web应用程序中没有文件夹(如文件夹结构中的情况),则默认的Tomcat web.xml位于TOMCAT_HOME/conf/web.xml

Either way, the relevant lines of the web.xml are 无论哪种方式,web.xml的相关行都是

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

so any file matching this pattern when found will be shown as the home page. 因此,找到时与此模式匹配的任何文件都将显示为主页。

In Tomcat, a web.xml setting within your web app will override the default, if present. 在Tomcat中,Web应用程序中的web.xml设置将覆盖默认值(如果存在)。

Further Reading 进一步阅读

How do I override the default home page loaded by Tomcat? 如何覆盖Tomcat加载的默认主页?

I already had index.html in the WebContent folder but it was not showing up , finally i added the following piece of code in my projects web.xml and it started showing up 我已经在WebContent文件夹中有了index.html,但是它没有显示出来,最后我在我的项目web.xml中添加了以下代码,它开始显示出来

  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping> 

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

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