0
HttpSession session;
session=request.getSession(false);
session.invalidate();

i m working on struts2 and hibernate framework.i have written this code in Logoutaction class but on pressing the back button in browser,its taking me to the old profile,which shouldn't happen after invalidating the session.So,should i use SessionMap or Map instead of HttpSession to invalidate the session?? i have searched for this but all i could find was the use of map and SessionMap.

Nidhi
  • 147
  • 3
  • 12

2 Answers2

0

you can use this method to logout from the session:

package simple;
import java.util.Map;
import javax.servlet.http.HttpSession;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionSupport;

public class LogoutAction extends ActionSupport {

    public String execute() throws Exception { 
     Map session = ActionContext.getContext().getSession();
session.remove("logined"); 
session.remove("context");
        return SUCCESS;
    }

}

Bourkadi
  • 738
  • 1
  • 7
  • 17
0

The problem of back button is that the browser is showing the cached page. To prevent browser caching,

you need to put following in header of your page.

"Cache-control","no-cache, no-store, must-revalidate"
"Pragma", "no-cache"
"Expires", "-1"
"Vary", "*"

You can do it either using interceptor or putting code in action or jsp page.

Removing Session code is to remove session only, it can not remove cache. But server side for every action you can check session by making interceptor and prevent user from performing action if session is destroyed.

It is not necessary to use map. But struts2 provide ServletAware interface to work with session. It is your choice to go with struts2 or not.

prem30488
  • 2,828
  • 2
  • 25
  • 57