0

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: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!

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.