chenzheng8975 发表于 2013-2-6 08:46:45

jsp页面验证用户是否已经登录

因为项目需要,在进入收藏夹页面时必须判断该用户是否已经登录,不然没有权限,自动跳转至登录页面
采用session的方法保存用户名


在servlet中写上:
String username=request.getParameter("username");
//创建一个session对象
HttpSession session = request.getSession();
//将用户名保存到session中
session.setAttribute("username",username);


在jsp页面中写上:
<%
String username=(String)session.getAttribute("username");
if(username==null || username.equals("")){
request.getRequestDispatcher("/info/loginindex.jsp").forward(request,response);
return;
}
%>
页: [1]
查看完整版本: jsp页面验证用户是否已经登录