| |

VerySource

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

Jsp write login, if judgment always error

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 22:20:01
| Show all posts |Read mode
Here is the code I wrote to verify that the login username and password are correct:

<% @ page contentType = "text / html"%>
<% @ page pageEncoding = "UTF-8"%>


<html>
    <head>
        <meta http-equiv = "Content-Type" content = "text / html; charset = UTF-8">
        <title> Verify user login information </ title>
    </ head>
    <body>

    <h1> Verify user login information </ h1>
    
   <jsp: useBean id = "Mybean" scope = "session" class = "org.me.hello.NameHandler" />
        
        <jsp: setProperty name = "Mybean" property = "*" />
       <%
           String uid = null, upwd = null;
           
           uid = request.getParameter ("username"). toString ();
           upwd = request.getParameter ("userpwd"). toString ();
        
            out.write (uid);
            out.write (upwd);
   
           if (uid == "zhx" .toString ()&&upwd == "1")
            {
               response.sendRedirect ("LogInSuccess.jsp");
            }
            else
            {
             
            }
       %>
       
    </ body>
</ html>



   The problem now is that when I enter the correct username, I always enter the LogInSuccess.jsp page, which means that the condition of if is false, but my input is correct, and I use out.write () to put The obtained user name and password are typed out correctly, but why can't it execute the correct result?
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-12 01:30:01
| Show all posts
uid = request.getParameter ("username"). toString ();
           upwd = request.getParameter ("userpwd"). toString ();
        
            out.write (uid);
            out.write (upwd);
   
           if (uid == "zhx" .toString ()&&upwd == "1")
            {
               response.sendRedirect ("LogInSuccess.jsp");
            }
            else
            {
             
            }
Why did you write .toString?
You replace uid == "zhx" .toString () with uid.equals ("zhx") and see
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-12 12:15:01
| Show all posts
Upstairs said that String is not a basic type and requires equals
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-12 19:15:02
| Show all posts
if (uid == "zhx" .toString ()&&upwd == "1")
            {
               response.sendRedirect ("LogInSuccess.jsp");
            }

Enter LogInSucce.jsp if it should be true ...
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-12 20:00:02
| Show all posts
String == and equals results are the same. . .
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-2-12 23:30:02
| Show all posts
Thank you both, replace it with uid.equals ("zhx"). Okay, but what's the problem with me? I didn't use tostring () at first, because it was always difficult to use, so I added
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