开发者

Logout Button doesn't work (session invalidate)

开发者 https://www.devze.com 2023-03-11 01:23 出处:网络
Hy! I have a jsp site called konto (engl. account) At the end i have a button that should invalidate the current session by clicking and redirect back to the loginpage but that doesn\'t work.

Hy!

I have a jsp site called konto (engl. account) At the end i have a button that should invalidate the current session by clicking and redirect back to the loginpage but that doesn't work.

Code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="konto" scope="session" class="at.korn.web.Konto"></jsp:useBean>
<% if (session.getAttribute("user")== null)
    {
%>
    <jsp开发者_StackOverflow:forward page="index.jsp"></jsp:forward>

<% }
if (request.getParameter("logout")!= null)
    {
    session.invalidate();
    %>
    <jsp:forward page="index.jsp"></jsp:forward>
   <% } %>

<% konto.holeKontostand(String.valueOf( session.getAttribute("user")));%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Konto</title>
    </head>
    <body>
        <h1>Kontoübersicht</h1>
        <p>Herzlich Willkommen <% out.print(session.getAttribute("user"));%> </p>
        <p>Ihr Kontostand beträgt: ${konto.ktostand} </p>
        <input type="submit" value="Logout" name="logout" />
        <br>
    </body>
</html>

The Error should be in that file. Please help!


You need to put the button in a <form> in order to get it to work.

<form>
    <input type="submit" value="Logout" name="logout" />
</form>

That said, mingling model, view and controller in a single JSP (view) isn't the best practice.

0

精彩评论

暂无评论...
验证码 换一张
取 消