Want to implement a logout function, there is a logout button on the page, I think a bit of it is written off, with the JS to the button added the onclick code, as follows
<%
Session = Request.getsession (true);
if (Session.isnew ())
{%>
<script language= "JavaScript" >
Alert ("Login timeout, please login again!");
top.location= ' main.jsp ';
Invalid session, page Jump here, return to the login page
</script>
<%
}
String type= (String) session.getattribute ("type");
String Show=null;
System.out.println ("Navigator User type:" +type);
if (type==null)
{
%>
<li class= "L1" ><a href= "register.jsp" target= "MainFrame" ><span> registration </span></a></li>
<li class= "L1" ><a href= "login.jsp" target= "MainFrame" ><span> login </span></a></li>
<%
}
Else
{
%>
<li class= "L1" ><input class= " Button "type=" button "Name=" Logout "value=" Logoff "
onclick= "logout ();"/></li> <li class=" L1 "><a href=" login.jsp "target=" MainFrame "><span> switch identities </span></a></li>
<%
System.out.println ("Navigator has been displayed correctly! "+type);
}
%>
Display different pictures according to different users,
<script language= "JavaScript" > in the same file, not an external function
function logout ()
{
Alert ("logout!");
<%system.ou.println (type); Session.invalidate ();%>
top.location= ' main.jsp ';
return false;
}
However, each time, even if you do not click Logout, the type will be displayed once, shown as null, and refresh the page again, user type display error
That means two.
1. Regardless of the location of the JSP script in the page, it will be executed, not because of the JS function triggered or not triggered by the change
2.JS scripts and JSP pages cannot share variables as if they were on different pages, so from JSP to JS simple, from JS to JSP more difficult
So log off or link to another page with a hyperlink.
JSP page Variable Scope problem