zoukankan      html  css  js  c++  java
  • J2EE 开发中首页的选择: index.htm 还是 index.jsp

    J2EE 开发中首页的选择: index.htm 还是 index.jsp

    J2EE 开发中,首页通常可以为 index.htm, index.html, index.jsp, default.htm,default.html,default.jsp 。你是否知道应该用哪一个呢?

    以前我以为是无所谓的,都可以。所以我 index.htm , 静态 HTML 页面,里面放一个跳转,
    <meta http-equiv="refresh" content="0;URL=xxx">
    转到一个动态页面,比如 http://www.test.com/mysystem/show_home

    最近的测试发现,这种办法是有问题的。主要是这个页面需要通过 filter 判断是否已经登录,然后跳转到“已登录首页”、“未登录首页”。这要求此页面不能被浏览器缓存 http://www.test.com/mysystem/。

    在 Tomcat 下,使用 index.htm, 并用 filter 强制要求浏览器不缓存页面,会导致 Tomcat 产生 HTTP response header 如下:
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Expires: -1
    Cache-Control: no-cache,no-store,private, max-age=0,s-maxage=0, must-revalidate
    Pragma: no-cache
    Last-Modified: Fri, 15 Oct 2010 01:31:59 GMT
    Accept-Ranges: bytes
    ETag: W/"680-1287106319011"
    Content-Type: text/html
    Content-Length: 680
    Date: Mon, 08 Nov 2010 07:53:40 GMT

    其中的 ETag 为 Tomcat 自动增加,Last-Modified 中时间为 index.htm 文件时间。
    再次访问 http://www.test.com/mysystem/, 客户端Firefox 会产生 HTTP request Header:
    If-Modified-Since 当前时间。
    这时候, 服务器端 Tomcat 对比 If-Modified-Since 与 index.htm 的文件时间(Last-Modified), 会直接告诉客户端"页面未修改"。这时浏览器就从本地缓存中取“未登录首页”,造成“已登录首页”、“未登录首页”在客户端混淆。

    问题原因在于“已登录首页”、“未登录首页”使用同一个网址, Tomcat 处理 index.htm 时产生了多余 ETag、错误的 Last-Modified。
    解决办法有多种,最简单的办法,就是把 index.htm 改为 index.jsp 。
    更进一步,为避免问题,我建议把 J2EE 项目中,所有直接访问的 html 文件,都改成后缀名为 jsp 。

    另外,似乎需要把
    <meta http-equiv="refresh" content="0;URL=xxx">
    改成
    <script language="JavaScript" type="text/javascript">
    document.location="xxx";
    </script>

    因为 meta refresh 在不同的浏览器中,被缓存的方式不同。因此建议避免使用 meta refresh。

    来自 http://www.cnblogs.com/jacklondon

  • 相关阅读:
    crystal report 用存储过程的问题。
    新的开始—2014
    C#基础(二)——C#中的构造函数
    C#基础(一)——C#中反斜杠/n与/r的区别
    Html基础(一)
    yield关键字, default关键字, 别名关键字
    让 wpf tabcontrol 延缓初始化每个tab item content
    MVC,MVP,MVVM(补充)
    Focus scope in WPF
    Wpf ItemsControl 开启UI Virtualization 的条件
  • 原文地址:https://www.cnblogs.com/jacklondon/p/1884684.html
Copyright © 2011-2022 走看看