jsp 真正能 禁止瀏覽器緩衝 的代碼 實測有效

來源:互聯網
上載者:User

這個問題困擾了我n久,之前的辦法是用js,現在終於找到瞭解決辦法了:

網上流行的版本:

<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
%>

我測試實際有效果的版本:

<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
%>

註:我是加在不希望讓瀏覽器緩衝的jsp中的,下面舉個我用的例子:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Expires" content="0">
        <meta http-equiv="Cache-Control" content="no-cache">
        <meta http-equiv="Cache-Control" content="no-store">
        <meta http-equiv="Pragma" content="no-cache">
        <title>列表頁</title>
        <meta http-equiv="description" content="列出使用者以供操作">
    </head>

    <body>
        <form name="manage" action="/user_manage/delUser" method="post">
            <s:iterator value="list" status="user">
                <input type="checkbox" name="user.delId"
                    value="<s:property value="id" />">
                <s:property value="username" />
                <s:property value="password" />
                <br />
            </s:iterator>
            <a href=javascript:manage.submit();>刪除選中的使用者</a>
        </form><br />
        <a href="/logout">退出登入</a>
        <s:debug></s:debug>
    </body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.