1

I'm a beginner with Tomcat/Java; I have a simple web application for which I would like to show a different <welcome-file> in web.xml depending on whether the application is being run locally development or deployed live.

Right now I have:

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

For local development I would like the <welcome-file> in web.xml to be index-dev.html for development and index-live.html for the deployed live application. Reason being I want to load different *.css and *.js depending on whether I'm local or live.

Any way in which I can achieve this setup?

4

3 回答 3

1

Live 应该总是有一个代理重定向到 tomcat 的 apache httpd。

这有多个优点:

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

问候

于 2012-09-20T12:49:08.610 回答
1

作为一个选项:制作一个 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 的子字符串。

于 2012-09-20T12:33:40.627 回答
1

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

于 2012-09-20T12:41:11.833 回答