Question

Following is my jsp code

<div id="menu-wrapper">
    <div id="menu">
        <ul>
            <li><a href="adminHome.jsp">Home</a></li>
            <li><a href="createCloud.jsp">Add New Cloud</a></li>
            <li><a href="cloudDetails.jsp">Cloud Details</a></li>                    
            <li><a href="newUser.jsp">Create Member</a></li>
            <li><a href="viewUser.jsp">Member Details</a></li>
            <li class="current_page_item"><a href="#">File Details</a></li>
            <li><a href="index.jsp" onclick="session.invalidate();">Log-out</a>   </li>
        </ul>
    </div>
    <!-- end #menu -->
</div>

On hitting the logout, I want to reset my session forcefully. How do I do that?

Was it helpful?

Solution

You can't put JSP code inside javascript functions like you are trying to do, because JSP runs on the server-side and is not related to javascript in any way.

Instead, make a JSP page called logout.jsp and put inside it:

<%
session.invalidate();
response.sendRedirect("index.jsp");
return;
%>

Then make your link to it:

 <a href="logout.jsp">Log-out</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top