我正在尝试使用jsp设计一个简单的登录系统。在登录页面,用户输入其核查被作为检查用户是否已经登录或会话在jsp中启动
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”我怎么检查是否会话已经建立执行他的用户名和密码??
* 我需要检查是否会话已经在配置文件每一页开始。所以,我想建立某种形式的功能,我可以在每一个JSP页面*
我应该怎么做的顶部调用?
我知道我应该Java代码在JSP中,但可以ü请告诉我什么是法,如果我尝试要做到这一点.. –
难道你没有在你的问题的代码?你可以把它放在过滤器中,然后每个请求都会检查会话。无需向JSP添加任何内容。 +1 – Sean