【问题标题】:Tomcat how to connect base site url to my project in server xmlTomcat如何在服务器xml中将基站点url连接到我的项目
【发布时间】:2018-11-03 09:16:45
【问题描述】:

我的服务器 xml 文件:

<Host name="XXX.XXX.XXX.XXX" 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" /> </Host>

我的项目位于 webapps 文件夹 (webapps/MyProject/)。当我转到站点 URL 时,tomcat 主页不是我的 MyProject 主页。

谢谢。

【问题讨论】:

  • 我知道 web.xml 中的欢迎文件标签,但事实并非如此。我想在 $TOMCAT_HOME/MyProject 中找到 MyProject 并更改主机标记( appBase="MyProject")中的 appbase 属性,但它不起作用。如何将 $TOMCAT_HOME/MyProject 连接到 myIP 或域名?

标签: java tomcat webserver tomcat7


【解决方案1】:

默认情况下,当您尝试使用以下 URL 访问它时,它打开的页面是默认的 tomcat 页面,

http://localhost:8080/

您需要覆盖该页面。在 $TOMCAT_HOME/conf/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>

默认 servlet 尝试按列出的顺序加载 index.* 文件。您可以通过在 $TOMCAT_HOME/webapps/ROOT 中创建 index.html 文件来轻松覆盖 index.jsp 文件。该文件包含一个新的静态主页或重定向到一个 servlet 的主页是很常见的。重定向看起来像:

<head>
<meta http-equiv="refresh" content="0;URL=http://localhost:8080/some/path/to/servlet/homepage/">
</head>

<body>
</body>

</html>

参考:https://wiki.apache.org/tomcat/HowTo#How_do_I_override_the_default_home_page_loaded_by_Tomcat.3F

【讨论】:

    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    相关资源
    最近更新 更多