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>