简体   繁体   中英

Page redirect on session empty doesn't seem to work

I'm tryting to redirect back to index.jsp if Session User is null and it doesn't seem to work. When the session is null I do get the response "request.getSession() is null"

JSP code.

<%
    if (null == session.getAttribute("User")) {
        // User is not logged in.  
        out.println("request.getSession() is null");
        String site = new String("http://localhost:8080/myproject/");
        response.setStatus(response.SC_MOVED_TEMPORARILY);
        response.setHeader("Location", site);
    }
%>

any help would be greatly appreciated!

This might help

URL newUrl = new URL("yourURL");
String url = newUrl.toString();
response.setStatus(response.SC_MOVED_TEMPORARILY); 
response.setHeader("Location", url);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM