> <%if (session.isNew()==true)
You need to do more than that, that only checks if session has just been created. So the 2nd time the page is loaded it will return false.
Main Topics
Browse All TopicsHi there,
I’m currently on an application that has an administrative module. I’m experiencing problems in clearing the sessions so as to log a user out and also to login as an admin and as a user of the application. I’m using a Java Bean for this purpose.
This is the code to check to see if there is a login session as an administrator or as a user. If there is no login session, the page will display a noAuthority.jsp ….. else it will show the page contents.
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean class = "Beans.User" id = "userid" scope = "application"></jsp:useBea
<jsp:setProperty name = "userid" property = "*"/>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%if (session.isNew()==true)
response.sendRedirect(resp
<%
boolean userAdmin = userid.checkUser();
if (userAdmin == false)
{%> <jsp:forward page = "noAuthority.jsp" /> <%}
else
{%>
<%
String loginName = userid.getUserName();
String loginPass = userid.getUserPass();
%>
Username: <% out.println(loginName); %> <br>
Password: <% out.println(loginPass); %> <br>
<h5> Hello, <%= userid.getUserName() %> You are Authorized! </h5> <br>
<b>Session ID: </b><%= session.getId() %><br>
<a href = "LogOut.jsp">logout test</a>
<%}%>
</body>
</html>
This is the Login_action page to process the login session with validation for username and password. The admin username is hardcoded and usernames are stored in a MySQL database.
<%if (session.isNew()==true)
response.sendRedirect(resp
<!-- Validation Page for Login-->
<!-- Open connection and execute query -->
<%
Class.forName("org.gjt.mm.
Connection connection = DriverManager.getConnectio
Statement statement = connection.createStatement
%>
<% ResultSet rs = statement.executeQuery("Se
<%
boolean userValidate, passValidate;
userValidate = false;
passValidate = false;
String name = " ";
if (rs != null)
{while (rs.next())
{name = rs.getString("Username");
if (name.equals(request.getPa
{userid.setUserName(name);
userValidate = true;
session.setAttribute("Pass
session.setMaxInactiveInte
String pass = rs.getString("password");
if (pass.equals(request.getPa
{userid.setUserPass(pass);
passValidate = true;}}}}
if (userValidate==true && passValidate == true)
{response.sendRedirect(res
else if (userValidate==true && passValidate == false)
{out.println("Password Error! Pls Try Again.");
%> <a href = "login.jsp"> BACK </a> <%}
else
{out.println("User Name Error! Pls Try Again.");}
%>
This is the logout page code. Basically clears the session created during the login.
<body>
<%if (session.isNew()==true)
response.sendRedirect(resp
<%session.invalidate();%>
<h4> You were being Logged out </h4> <br>
<a href = "login.jsp"> Login </a><br>
<b>Session ID: </b><%= session.getId() %>
</body>
Currently, the problem that I’m facing is that when I logout of the application, I’m still able to access a page by typing the URL of the page into the browser twice. For example,
http://localhost:8080/newt
Also, sometimes, there is an error page that shows the message; forward statement cannot proceed because a response has been committed.
Any help on this is greatly appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>Also, sometimes, there is an error page that shows the message; forward statement cannot proceed because a response has been committed.
That is because the response has been committed after you try to redirect to another page :
Try to move your sendRedirect method before any html tags.
for example :
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean class = "Beans.User" id = "userid" scope = "application"></jsp:useBea
<jsp:setProperty name = "userid" property = "*"/>
<%if (session.isNew()==true)
response.sendRedirect(resp
<%
boolean userAdmin = userid.checkUser();
if (userAdmin == false)
{%> <jsp:forward page = "noAuthority.jsp" /> <%}
else
{%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
...
objects is correct, try to use the following to check the session :
if (session.getAttribute("Pas
Dear Participants,
All your help has reaped success!!! I've managed to solve the problem.
With regards to objects, i can't use the scope="session" but the scope="application" tag. The former will constantly "lock" me out of the application, even if i'm logged on as the administrator.
The code that i've amended is listed below:
<% boolean userAdmin = userid.checkuser();
%>
<% if (session.isNew() == true || userAdmin == false || session.getAttribute("Pass
{
response.sendRedirect(resp
}
else {
displayed contents here......
}
%>
Business Accounts
Answer for Membership
by: keneticintroublePosted on 2003-11-30 at 18:04:46ID: 9847387
Additional Queries:
I'm using the Tomcat Web Server to host the JSP so is there such a thing as a tomcat cache that stores sessions?? If so, how can i clear that because i think my codes recognise that as a session instead of the admin module's session.
Thanks again