I'm trying to log out users and destroy the session by having the user click on a link to a jsp that is not mapped to a servlet.
In my logout.jsp I have the following (Edit added remove since posting but its still not clearing the session)
<%
session.removeAttribute("loggedin");
session.removeAttribute("loggedUsrID");
session.removeAttribute("loggedUsrFName");
session.invalidate();
response.sendRedirect(request.getContextPath());
%>
When clicked on I'm redirected to the index.jsp, however when I close the browser and then launch the application again in netbeans and click on a link I see the following in the address bar
http://localhost:8084/myapp/register.jsp;jsessionid=0002B8466FB3CC578C56E61017E9FD3C
For completeness I'm including the section of my user controller which logs in the user and sets the session in case I'm doing something wrong there
//Handle User Login
private String logInToSite(HttpServletRequest request,
HttpServletResponse response) {
String url;
String message;
// get values from form
String pNum = request.getParameter("phoneNumber");
String upwd = request.getParameter("password");
//validate the values to check for empty values in case JS registration check has failed.
if(pNum.length()==0 ||upwd.length()==0){
message="You have not filled out the required fields.";
request.setAttribute("message", message);
url = "/login.jsp";
return url;
}
//Format the phone number
String mPNum=UserDB.formatPhoneNumber(pNum);
User user = UserDB.loginUser(mPNum, upwd);
if(user==null){
message="User null";
request.setAttribute("message", message);
url = "/loginerror.jsp";
}else{
String hpwd = user.getPwd();
if(BCrypt.checkpw(upwd, hpwd)==false){
message="password didn't match";
request.setAttribute("message", message);
url="/loginerror.jsp";
}
else{
boolean logged=false;
HttpSession session = request.getSession();
session.setAttribute("loggedUsrID", user.getUserID());
session.setAttribute("loggedUsrFName", user.getFName());
session.setAttribute("loggedin",logged=true);
url="/schedule/welcome.jsp";
}
}
return url;
}