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.
精彩评论