浏览 4326 次
锁定老帖子 主题:关于webwork session登陆验证
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-01-21
BaseAction如下: import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.lang.*; import com.opensymphony.webwork.ServletActionContext; import com.opensymphony.xwork.ActionSupport; public class BaseAction extends ActionSupport { protected transient final Log log = LogFactory.getLog(getClass()); private String loginId=""; public String getLoginId() { return loginId; } protected boolean checkNoLogin(){ //getSession().setMaxInactiveInterval(1); HttpSession session = getSession(); loginId = (String)session.getAttribute("userSession"); System.out.println("loginId:"+loginId); if(StringUtils.isBlank(loginId)) { return true; } return false; } /** * Convenience method to get the request * @return current request */ protected HttpServletRequest getRequest() { return ServletActionContext.getRequest(); } /** * Convenience method to get the response * @return current response */ protected HttpServletResponse getResponse() { return ServletActionContext.getResponse(); } /** * Convenience method to get the session */ protected HttpSession getSession() { return getRequest().getSession(); } loginAction.java如下: public String login() throws Exception { System.out.println("loginId:"+loginId); System.out.println("password:"+password); if (loginDao.checkUserExists(loginId,password) == false) { addFieldError("loginIdNoExists", "用户名不存在!"); return ERROR; } else if (loginDao.checkUserSuccess(loginId,password) == false) { addFieldError("passwordNoMatch", "用户密码错误!"); return ERROR; } else { System.out.println("login success!"); HttpSession session = getSession(); session.setAttribute("userSession", loginId); System.out.println("成功登录!"); } return SUCCESS; } 但是登陆成功之后,在其他的模块Condition.java中 public String condition() throws Exception { if(checkNoLogin()) return "login"; return SUCCESS; } 调用BaseAction的checkNoLogin方法,取得登陆成功之后保存在session中的userSession,为什么会是null呢? 请各位解答一下.或者有其他的方式来验证用户是否登陆成功的方式,谢谢!!! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-02-11
用filter不行么?
|
|
返回顶楼 | |