Hiten Hiten - 1 year ago 130
Java Question

How to redirect jsp page after session expired?

if(session == null) {
System.out.println("Not Expire");

HttpSession sess = request.getSession(false);
String email = sess.getAttribute("email").toString();
Connection conn = Database.getConnection();
Statement st = conn.createStatement();
String sql = "select * from login where email = '" + email + "' ";
ResultSet rs = st.executeQuery(sql);

I tried to redirect the login.jsp page when session is expired.
But I am geeting error in "String email = sesss.getAttribute("email").toString();".

So anyone please help me to solve this error.

Basically I want to redirect to login.jsp page when the session is expired.

Answer Source

I tried this and its working fine for me.

    if(session.getAttribute("email") == null) {
       return ;

I just put return statement and It will redirect to "login.jsp" when the session is expired.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download