jsp網站開發安全知道---”頁面失效“
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", -10);
%>
在登陸頁面和登陸後頁面均加入這段代碼即可
注意,一定要在登陸頁面(或類似功能的頁面使session無效)
客戶端方法:
meta是用來在HTML文檔中模擬HTTP協議的響應頭報文。meta 標籤用於網頁的<head>與</head>中,meta 標籤的用處很多。meta 的屬性有兩種:name和http-equiv。name屬性主要用於描述網頁,對應於content(網頁內容),以便於搜索引擎機器人查找、分類(目前幾乎所有的搜索引擎都使用網上機器人自動查找meta值來給網頁分類)。這其中最重要的是description(站點在搜索引擎上的描述)和keywords(分類關鍵詞),所以應該給每頁加一個meta值。比較常用的有以下幾個:
name 屬性
1、<meta name="Generator" contect="">用以說明生成工具(如Microsoft FrontPage 4.0)等;
2、<meta name="KEYWords" contect="">向搜索引擎說明你的網頁的關鍵詞;
3、<meta name="DEscription" contect="">告訴搜索引擎你的站點的主要內容;
4、<meta name="Author" contect="你的姓名">告訴搜索引擎你的站點的製作的作者;
5、<meta name="Robots" contect=
"all|none|index|noindex|follow|nofollow">
其中的屬性說明如下:
設定爲all:文件將被檢索,且頁面上的鏈接可以被查詢;
設定爲none:文件將不被檢索,且頁面上的鏈接不可以被查詢;
設定爲index:文件將被檢索;
設定爲follow:頁面上的鏈接可以被查詢;
設定爲noindex:文件將不被檢索,但頁面上的鏈接可以被查詢;
設定爲nofollow:文件將不被檢索,頁面上的鏈接可以被查詢。
http-equiv屬性
1、<meta http-equiv="Content-Type" contect="text/html";charset=gb_2312-80">
和 <meta http-equiv="Content-Language" contect="zh-CN">用以說明主頁製作所使用的文字以及語言;
又如英文是ISO-8859-1字符集,還有BIG5、utf-8、shift-Jis、Euc、Koi8-2等字符集;
2、<meta http-equiv="Refresh" contect="n;url=http://yourlink">定時讓網頁在指定的時間n內,跳轉到頁面http;//yourlink;
3、<meta http-equiv="Expires" contect="Mon,12 May 2001 00:20:00 GMT">可以用於設定網頁的到期時間,一旦過期則必須到服務器上重新調用。需要注意的是必須使用GMT時間格式;
4、<meta http-equiv="Pragma" contect="no-cache">是用於設定禁止瀏覽器從本地機的緩存中調閱頁面內容,設定後一旦離開網頁就無法從Cache中再調出;
5、<meta http-equiv="set-cookie" contect="Mon,12 May 2001 00:20:00 GMT">cookie設定,如果網頁過期,存盤的cookie將被刪除。需要注意的也是必須使用GMT時間格式;
6、<meta http-equiv="Pics-label" contect="">網頁等級評定,在IE的internet選項中有一項內容設置,可以防止瀏覽一些受限制的網站,而網站的限制級別就是通過meta屬性來設置的;
7、<meta http-equiv="windows-Target" contect="_top">強制頁面在當前窗口中以獨立頁面顯示,可以防止自己的網頁被別人當作一個frame頁調用;
8、<meta http-equiv="Page-Enter" contect="revealTrans(duration=10,transtion=
50)">和<meta http-equiv="Page-Exit"
contect="revealTrans(duration=20,transtion
=6)">設定進入和離開頁面時的特殊效果,這個功能即FrontPage中的“格式/網頁過渡”,不過所加的頁面不能夠是一個frame頁面。
上面是從網上弄到的信息。
我使用的開發工具是MyEclipse,當我創建一個Jsp頁面時,MyEclipse就會爲我自動創建一個模版,如:
1.MyJsp.jsp:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<body>
<html:form action="userAction">
Username:<html:text property="username"></html:text>
<html:submit value="提交"/>
</html:form>
</body>
2.MyJsp1.jsp:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<body>
username:${requestScope.userForm.username}
</body>
3.struts-config.xml:
<form-beans>
<form-bean name="userForm" type="com.andy.struts.form.UserForm"></form-bean>
</form-beans>
<forward name="toMyJsp1" path="/MyJsp1.jsp"></forward>
<action-mappings>
<action path="/userAction" type="com.andy.struts.action.UserAction" name="userForm" scope="request" validate="true">
</action>
</action-mappings>
4.UserForm:
package com.andy.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class UserForm extends ActionForm {
private String username=null;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}