[当我单击一次注销链接时,它不会返回,但是当我单击两次注销链接时,它会返回到前一页或上一页

问题描述 投票:0回答:1

我正在使用netbens8中的jsp进行注销的代码。我的数据库在mysql中。我正在尝试为注销超链接编写代码。我已经完成了以下代码。但是我的问题是当我单击一次注销链接时,它不返回,但是当我单击两次注销链接时,它返回了上一页或上一页。我在filelist.jsp页面中创建了一个链接单击此处以注销。当我单击此链接时,它将重新编入logout.jsp页面。我想限制用户返回。怎么做?我在代码某处出错了吗?请建议我。在此先感谢:)

这是我的filelist.jsp页面

<%-- 
    Document   : filelist
    Created on : 22 Oct, 2019, 7:48:04 PM
    Author     : Z0009289
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="com.servlet.db.DB"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
   
    
%>    
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="bootstrap.css" rel="stylesheet" type="text/css">
        <title>file_list Page</title>
        
    </head>
    <body>
        <a href="logout.jsp">Click here to logout</a>
         
    </body>
</html>

这是我的logout.jsp页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    session = request.getSession();
    
    String userid = "";
    if ((session.getAttribute("userid") == null) || (session.getAttribute("userid") == "")) {
        response.sendRedirect("login.jsp");
    }
    else{
        userid = session.getAttribute("userid").toString();
    }
    
    
    
    
%>    
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Log out Page</title>
    </head>
    <body>
        
        <h2>Are you sure to logout???</h2>
        <% 
            response.setHeader("Cache-Control","no-cache");
            response.setHeader("Cache-Control","no-store");
            response.setHeader("Pragma","no-cache");
            response.setDateHeader ("Expires", 0);
        %>
        
        <a href="signout.jsp"><button type="submit">Logout</button></a>
    </body>
</html>

这是我的signout.jsp页面

  <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <% 
            response.setHeader("Cache-Control","no-cache");
            response.setHeader("Cache-Control","no-store");
            response.setHeader("Pragma","no-cache");
            response.setDateHeader ("Expires", 0);
%>

      <%
    
    session = request.getSession();
    
    String uname = "";
    if ((session.getAttribute("userid") == null) || (session.getAttribute("userid") == "")) {
        response.sendRedirect("login.jsp");
    }
    else{
        uname = session.getAttribute("userid").toString();
    }
    
    
    
    
%>
        <!DOCTYPE html>
        <html>

        <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <title>Sign out Page</title>
        </head>

        <body>
          <%  
        response.setHeader("Cache-Control","no-cache");
        response.setHeader("Cache-Control","no-store");
        response.setHeader("Pragma","no-cache");
        response.setDateHeader ("Expires", 0);
        if(session.getAttribute("userid") != null){
            session.removeAttribute("userid");
            request.getSession(false);
            session.setAttribute("userid", null);
            session.invalidate();
            response.sendRedirect("login.jsp");
            
        }
        
        %>
        </body>

        </html>
java mysql jsp servlets netbeans
1个回答
0
投票

此代码段将为您服务并解决您的错误

Logout.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

<head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</head>
----//body tags
<%
session.invalidate();
response.setHeader("Cache-Control","no-store"); 
response.setHeader("Pragma","no-cache"); 
response.setDateHeader ("Expires", 0);
%>
<jsp:forward page="index.jsp"></jsp:forward>

a href

 <li><a href="logout.jsp">Logout</a></li>
© www.soinside.com 2019 - 2024. All rights reserved.