繁体   English   中英

Tomcat:本地和实时设置的不同欢迎文件

[英]Tomcat: Different welcome-file for local and live setup

我是Tomcat / Java的初学者; 我有一个简单的Web应用程序,我想在web.xml显示不同的<welcome-file> ,具体取决于应用程序是在本地开发还是实时部署。

现在我有:

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

对于地方发展我想<welcome-file>web.xmlindex-dev.html发展和index-live.html的部署实时应用。 原因是我想加载不同的*.css*.js取决于我是本地的还是现场的。

我可以通过哪种方式实现此设置?

作为选项:将jsp文件作为欢迎页面。

在该jsp文件中分析当前客户端位置(本地计算机与否),并转发到相关页面。

其他编辑:

您的jsp有一个预定义的request对象。

用它来获取客户端ip,就像这样:

<%
    String remoteIp = request.getRemoteAddr();
%>

将它与localhost地址进行比较,可以通过以下方式获得:

<%
    InetAddress address = InetAddress.getLocalHost();
    String localhostIp = address.getHostAddress();
%>

并使用jsp:forward转发到相关页面。

<%
    // getting jsp (servlet) client ip
    String remoteIp = request.getRemoteAddr();

    // getting local ip
    InetAddress address = InetAddress.getLocalHost();
    String localhostIp = address.getHostAddress();

    // checking and forwarding
    if(localhostIp.equals(remoteIp)){
%>
     <jsp:forward page="localhost.html"/>
<%}else{%>
    <jsp:forward page="remote.html"/>
<%}%>

附加编辑:

确保localhostIp仅包含IP地址,否则使用String方法获取带有ip-address的子字符串。

创建一个标题页面(将包含在所有页面中,包括欢迎页面)。 写一个<c:if>来做一个简单的检查。 我不认为servlet规范支持基于请求机器的IP地址的不同欢迎页面。 理想情况下,任何web-app都应该从访问它的位置提供相同的页面

Live应该总是有一个apache httpd who proxy-redirect to tomcat。

这有多个优点:

  • 如果tomcat关闭,你可以定义一个“请耐心等待/稍后回来”info.html
  • 使用awstats你可以分析流量
  • 您可以定义实时JS / CSS-directorys来释放tomcat

问候

暂无
暂无

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

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