0

java页面中的代码

protected void onSubmit() {
            System.out.println("login name inner the submit function:"+this.loginName);

        if(loginName == null || password == null) {
            logger.error("login failed - login name " + 
                    (loginName!=null ? "is set (trimmed length=" + 
                            loginName.trim().length()+")" : "is null") + 
                    " and password " + 
                    (password!=null ? "is set" : "is null") + ".");
            error(getLocalizer().getString("login.error", null));
            return;
        }

        User user = JtracApplication.get().authenticate(loginName, password);
        System.out.println("USER:"+user);
        if (user == null) {
            /*
             * ================================
             * Login failed!
             * ================================
             */
            logger.error("login failed - Authentication for login name '"+
                    loginName + "' not successful");
            error(getLocalizer().getString("login.error", null));
        } else {
            /*
             * ================================
             * Login success!
             * ================================
             */

            /*
             * Set Remember me cookie if checkbox is checked on page.
             */
            if(rememberMe) {
                Cookie cookie = new Cookie("jtrac", loginName + ":" + JtracApplication.get().getJtrac().encodeClearText(password));
                cookie.setMaxAge(30 * 24 * 60 * 60); // 30 days in seconds 
                String path = getWebRequestCycle().getWebRequest().getHttpServletRequest().getContextPath();
                cookie.setPath(path);
                getWebRequestCycle().getWebResponse().addCookie(cookie);
                logger.debug("remember me requested, cookie added, " + WebUtils.getDebugStringForCookie(cookie));
                System.out.println("cookies:"+cookie);
                temp=cookie;
            }

            /*
             * Setup session with principal
             */
            JtracSession.get().setUser(user);

            /*
             * Proceed to bookmarkable page or default dashboard
             */
            if (!continueToOriginalDestination()) {
                setResponsePage(DashboardPage.class);
            }
        }
    } // end onSubmit()

我不知道如何在变量中设置 cookie 值并将其传递给我的 html 页面,请尽早帮助我。页

4

1 回答 1

0

希望这两个链接对您有所帮助。

  1. 获取/设置 Cookie
  2. JSP - Cookie 处理
于 2013-04-18T08:30:33.397 回答