-1

I first create a html file to input Username & Passwword:

<body>
<center>
    <h1>Login Section</h1>
    <form method="post" action ="getInfo.jsp">
        Username <input type="text" name="UserID"><br>
        Password <input type="password" name="pass"><br>
        <input type="submit" name="submit">
    </form>
</center>
</body>

Then the first.jsp file receive the Username & Password (check cookie also, everything runs fine):

<form method="get" action="showInfo.jsp">
    <%      
        String name = request.getParameter("UserID");
        String pass = request.getParameter("pass");
        Cookie pie = new Cookie(name, "nothing_to_do_here");
        pie.setMaxAge(60 * 60 * 7);
        response.addCookie(pie);

        Cookie[] cookies = request.getCookies();
        boolean isLogin = false;
        if (cookies != null) {
            Cookie cookie;
            for (int i = 0; i < cookies.length; i++) {
                cookie = cookies[i];
                if (name.equals(cookie.getName())) {
                    isLogin = true;
                    break;
                }
            }
        }

        if (isLogin == true) {
            out.print("Welcome back " + name);

        } else {
            out.print("Welcome " + name);

        }

    %>

    <a href="showInfo.jsp">Click here</a>
    </form>

After click the "Click here" button, I want to show the Username & Password but it returns NULL.

<body>
<center>
    <h1>Your ID and Password</h1>
    <%
        String id = (String)session.getAttribute((String)"UserID");
        String pass = (String)session.getAttribute((String)"pass");
        out.print(id);
        out.print(pass);
        %>
</center>
</body>

Anybody helps me to show them please.

Vu Nam
  • 1
  • May be you looking for this.... [See This](http://stackoverflow.com/questions/22369717/how-to-pass-value-from-one-jsp-to-another-jsp-page) – bud-e Oct 11 '14 at 02:25

1 Answers1

0

Well, you aren't SETTING those session variables, you're only trying to get them, you need something like
session.setAttribute("UserID", "someuserid");
Additionally, you should probably use session to store the login information, not cookies. Clients can view and edit cookies, with your current code all i have to do is set a cookie saying
Bob : nothing_to_do_here
and your application would assume i was Bob.

Zachary Craig
  • 2,192
  • 4
  • 23
  • 34