简体   繁体   中英

redirect user to login page

I'm running a J2EE application and need to redirect the user to login page if the session is inactive.

I basically want to use the below javascript code to get the session last accessed time and compare with the current time, and if its more than the session timeout I will logout:-

<script>

        setInterval(function() {

            console.log('MaxInactive Interval ==  ' + <%=new Date(session.getLastAccessedTime())%> );

        }, 10000);
    </script>

I get the below error on the console.log line:-

Uncaught SyntaxError: missing ) after argument list

Here is the display from the sources tab:-

console.log('MaxInactive Interval ==  ' + Sun May 31 20:33:17 EDT 2015 );

You should place the single quote at the end of console.log argument

    setInterval(function() {

        console.log('MaxInactive Interval == <%=new Date(session.getLastAccessedTime())%>' );

    }, 10000);
</script>

And you don't need the + operator, you cannot concatenate javascript string with java expressions.

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