检查用户是否已经登录或在jsp中启动了会话 [英] Checking if a user is already logged in or the session is started in jsp
本文介绍了检查用户是否已经登录或在jsp中启动了会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jsp设计一个简单的登录系统.在登录页面中,用户输入其用户名和密码,验证后将以该用户名和密码执行
I am trying to design a simple login system using jsp. In the login page, the user inputs his username and password which on verification gets executed as
if username and password combination exists, then
{
HttpSession session = request.getSession(false);
if (session == null) {
// Session not created yet. So we do it now.
session = request.getSession();
session.setAttribute("id",idvariable );
response.sendRedirect("home.jsp");
// I redirect them to their profile home pages
}
else {
// Session is already created.
response.sendRedirect("home.jsp");
// So i again redirect them to their home page
}
}
现在在"home.jsp"中,如何检查会话是否已创建??
Now in the "home.jsp" how do i check if the session has already been created ??
* 我需要检查会话是否已经在配置文件中的每个页面上启动.所以我想创建某种可以在每个jsp页面顶部调用的函数*
我该怎么办??
推荐答案
使用JSP Prelude
,它将jsp添加到所有jsps的开头.并检查会议是否已经存在.
Use JSP Prelude
which adds the jsp to the begining of all jsps. And check if the sesion already exists.
参考:
这篇关于检查用户是否已经登录或在jsp中启动了会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文