【发布时间】:2016-09-30 08:30:03
【问题描述】:
<%
if(session == null) {
System.out.println("Expire");
response.sendRedirect("/login.jsp");
}else{
System.out.println("Not Expire");
}
%>
<%
HttpSession sess = request.getSession(false);
String email = sess.getAttribute("email").toString();
Connection conn = Database.getConnection();
Statement st = conn.createStatement();
String sql = "select * from login where email = '" + email + "' ";
ResultSet rs = st.executeQuery(sql);
%>
我尝试在会话过期时重定向 login.jsp 页面。 但我在“String email = sesss.getAttribute("email").toString();”中遇到错误。
所以请任何人帮我解决这个错误。
基本上我想在会话过期时重定向到 login.jsp 页面。
【问题讨论】:
-
错误是什么?
-
您需要 1) 将整个批次放入
if或 2)return。或者 3) 永远,永远,再也不使用 scriptlet - 十年来它们一直是非常糟糕的做法;没有人应该使用它们。 -
@BoristheSpider 我支持你。 3,尤其是数据库连接这件事让我不寒而栗。
-
我更改了一些代码。 if(session.getAttribute("email") == null) { System.out.println("Expire"); response.sendRedirect("login.jsp"); }else{ System.out.println("未过期");我会得到“过期”文本,但仍然没有重定向到“login.jsp”页面。并面临第二批相同的错误。