2014-02-17 25 views
0

在我的jsp頁面我有註銷按鈕。當我點擊它時,我應該調用一個servlet幷包含session.invalidate()代碼或調用一個jsp幷包含此代碼,或者將代碼包含在每個jsp頁面中我有註銷按鈕的地方。在哪裏包括session.invalidate()代碼

logout.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
    <% 

     session.invalidate(); 
     response.sendRedirect("index.html"); 
    %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>logout</title> 
    <%  
    response.addHeader("Cache-Control", "no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0"); 
    response.addHeader("Pragma", "no-cache"); 
    response.addDateHeader ("Expires", 0); 
    %> 
</head> 
<body> 

</body> 
</html> 
+1

這取決於你。你想把它放在哪裏?沒有單一的答案。 – EJP

回答

1

你只需要一個單一的註銷page.And一旦你從任何頁面上的註銷按鈕點擊,你可以有你的web application.But的每一個頁面上的註銷按鈕你應該重定向到你的logout.jsp文件。

您可以製作頁眉頁腳。您可以添加您的註銷按鈕。您可以將此頁面包含在需要註銷按鈕的其他每個jsp頁面上,而不必在每個頁面上寫註銷按鈕代碼。