| |

VerySource

 Forgot password?
 Register
Search
View: 753|Reply: 5

For a long time, please give pointers to heroes!

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-22 10:40:01
| Show all posts |Read mode
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!
Reply

Use magic Report

0

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 United States

Post time: 2020-5-9 19:00:02
| Show all posts
Disable page caching, it displays the value of the previous cache every time!
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

 Author| Post time: 2020-5-22 19:30:01
| Show all posts
Isn't it

// Set the page not to cache
response.setHeader ("Pragma", "No-cache");
response.setHeader ("Cache-Control", "no-cache");
response.setDateHeader ("Expires", 0);

Did you write the code above?
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 United States

Post time: 2020-5-25 23:15:01
| Show all posts
Cache less once?
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-30 14:15:01
| Show all posts
Try to write like this

for (int i = 0; i <4; i ++) {
    String rand = String.valueOf (random.nextInt (10));
    String sRand + = rand;
    // Display the authentication code in the image
    g.drawString (rand, 11 * i + 1,12);
}

// session save rand
session.setAttribute ("rand", sRand);
Reply

Use magic Report

1

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-30 17:00:01
| Show all posts
Maybe the above is wrong
should be
 String sRand = "";
Write this sentence in for
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list