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.