1
2
3
4
5
6
7
8
9 |
UserDao userDao = new
UserDao(); User u = userDao.login(user); <span style= "color: rgb(0, 128, 0);" > // 调用登录方法。</span> result = new
HashMap(); if (u != null ){ result.put( "result" , true ); ServletActionContext.getRequest().getSession().setAttribute( "user" ,u); } else { result.put( "result" , false ); } |
参考:http://hi.baidu.com/timer_ysh/item/460ccef6564c99cf531c2699
然后在jsp里获取session,如果为空,重定向到登录页面:
1
2
3
4 |
User user = (User)session.getAttribute( "user" ); if (user == null ){ response.sendRedirect( "login.jsp" ); }<span style= "color: rgb(153, 51, 0);" ><br></span> |
action里设置session,布布扣,bubuko.com
原文:http://www.cnblogs.com/skyeyh/p/3730288.html