|
There is a rand.jsp page that generates a verification code:
// Take a randomly generated authentication code (4 digits)
String sRand = "";
for (int i = 0; i <4; i ++) {
String rand = String.valueOf (random.nextInt (10));
sRand + = rand;
// Display the authentication code in the image
g.drawString (rand, 11 * i + 1,12);
}
// session saves rand
session.setAttribute ("rand", sRand);
Landing page index.jsp:
<form action = "<% = request.getContextPath ()%> / login.do" name = "loginform" method = "post">
<td> User: <input type = textbox name = "username" value = "" /> </ td>
<td> Password: <input type = password name = "password" value = "" /> </ td>
<td> Verification code: <input type = textbox name = "randt" value = "" />
<img border = 0 src = "rand.jsp"> </ td>
<td>
<input type = submit value = "login" name = "loginsub">
<input type = reset value = "override" name = "loginres">
</ td>
<% = session.getAttribute ("rand")%>
Why does the value of session.getAttribute ("rand") differ from the value of <img border = 0 src = "rand.jsp>? Session.getAttribute (" rand ") shows <img border = 0 The previous value of src = "rand.jsp>, if it is the first session.getAttribute (" rand ") shows null, but <img border = 0 src =" rand.jsp> has a value
But in LoginAction
session.getAttribute ("rand");
String rand = (String) session.getAttribute ("rand");
String randt = forms.getRandt ();
if (randt.equals (rand))
{equal}
else {不等}
They are equal, but they will be prompted when they are filled in for the first time, and they will be equal in the future.
Ask you heroes, what is the reason for this? What should I do?
First, thank you! |
|