注册后如何进行“首次登录时强制更改密码”

时间:2011-09-16 07:15:56

标签: struts

我的行动是:

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 个答案:

答案 0 :(得分:1)

(仅供参考,发布的代码与问题完全无关。)

为什么要将当前用户存储在列表中?这是一个单一的用户。

在任何情况下,您都需要跟踪用户是否首次登录数据库。你可以用一个简单的标志来做到这一点,或者从长远来看,通过跟踪他们登录的次数来做到这一点。

如果“已登录?”未设置标志,或登录次数为零,将其重定向到“更改密码”页面。此时,您需要确保他们实际上已经更改了密码并禁止网站移动,直到他们这样做。