我有两个jsps。一个是login_first.jsp
,另一个是main.jsp
。提交后login_first.jsp
,我打电话main.jsp
。它工作正常。
我有注销按钮,main.jsp
其中将控制权发送回login_first.jsp
. 它执行login_first.jsp
但页面未加载。请帮忙。
login_first.jsp
<%@ page session="false" %>
<%
try {
HttpSession session = request.getSession(true);
if ("Submit".equals(request.getParameter("SubmitButton"))) {
session.setAttribute("userLoggedIn", "true");
response.sendRedirect("main.jsp");
return;
} else {
session.setAttribute("userLoggedIn", "false");
session.invalidate();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<form name="loginForm" method="post">
<table>
<tr>
<td><input type="submit" name="SubmitButton" value="Submit" class=button/></td>
</tr>
</table>
</form>
</body>
<%
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("login_first.jsp");
return;
}
%>
</html>
主.jsp
<%@ page session="false" %>
<%
try {
HttpSession session = request.getSession(false);
if (session != null && "true".equals(session.getAttribute("userLoggedIn"))
&& !"Logout".equalsIgnoreCase(request.getParameter("logout"))) {
// do work
} else {
if (session != null) {
session.setAttribute("userLoggedIn", "false");
}
response.sendRedirect("login_first.jsp");
return;
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<form name="creditCardForm" target="formresponse" autocomplete="off" method="post">
<table width="50%" border=0 cellpadding=3 cellspacing=1>
<tr>
<td>
<div align="right">
<input name="logout" type="submit" class=button value="Logout">
</div>
</td>
</tr>
</table>
<iframe name="formresponse" width="0" height="0" style="visibility:hidden"></iframe>
</form>
</body>
<%
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("login_first.jsp");
return;
}
%>
</html>