2011-09-16 48 views
0

我的行動後:我怎樣才能讓「先嚐試登錄時強制更改密碼」登錄

public class LoginAction extends org.apache.struts.action.Action { 

    /** 
    * This is the action called from the Struts framework. 
    * @param mapping The ActionMapping used to select this instance. 
    * @param form The optional ActionForm bean for this request. 
    * @param request The HTTP Request we are processing. 
    * @param response The HTTP Response we are processing. 
    * @throws java.lang.Exception 
    * @return 
    */ 
    @Override 
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
      HttpServletRequest request, HttpServletResponse response) 
      throws Exception { 
     LoginForm loginForm = (LoginForm) form; 
     HttpSession session = request.getSession(true); 

     String userName = loginForm.getUsername(); 
     System.out.print("name::" + userName); 

     List list=new ArrayList(); 
     String passWord = loginForm.getPassword(); 
     System.out.print("here is Actionform::" + loginForm.toString()); 
     list = StudentloginDAO.studentLogin(userName, passWord); 





     if (list.size() > 0) { 
       int id = (Integer) list.get(0); 

     System.out.println("id is" + id); 
     System.out.println(" List :: " + list.size()); 
     System.out.println(" List :: " + list); 
     List<StudentSessionObjectStore> list1 = StudentSessionObject.studentSessionObject(id); 
     System.out.println("new list" + list1.size()); 
     System.out.println("new list value" + list1); 
     session.setAttribute("getsessionObject", list1); 
     System.out.println("the Action attribute" + session.getAttribute("getsessionObject")); 
      return mapping.findForward(Constants.ACTION_FORWARD_SUCCESS); 
     } else { 
      request.setAttribute("LoginResult", Constants.ACTION_FORWARD_FAILURE); 
      return mapping.findForward(Constants.ACTION_FORWARD_FAILURE); 
     } 
    } 
} 

我的問題是我想去changePassword.jsp爲強制更改密碼當用戶第一次登錄。

有人可以幫我嗎?

回答

1

(僅供參考,張貼的代碼是完全不相干的問題。)

你爲什麼要保存當前的用戶列表中?這是一個用戶。

無論如何,您需要跟蹤它是否是用戶在數據庫中的首次登錄。你可以用一個簡單的標誌來做到這一點,或者從長遠來看,通過跟蹤他們已經登錄多少次來做到這一點。

如果「已經登錄?」標誌未設置或登錄次數爲零時,將它們重定向到「更改密碼」頁面。此時,您需要確保他們實際上已更改密碼並禁止網站移動,直到他們這樣做。