如何在JSP中检查两个字符串是否相等? [重复]

时间:2022-12-21 11:28:40

This question already has an answer here:

这个问题在这里已有答案:

how to check whether these two strings are equal in Java using if...else block.

如何使用if ... else块检查Java中这两个字符串是否相等。

            String passw1=(String)request.getParameter("pass");
            System.out.println("value of passw1"+passw1);
            String passw2=(String)request.getParameter("pass1");
            System.out.println("value of passw1"+passw2);
            //String a=passw1;//String b=passw2;
            if(passw1.equals(passw2))
            {
            out.println("Password matches");

2 个解决方案

#1


2  

Scriplet accept java code so its simple like this

Scriplet接受java代码,所以它很简单

    <% 
 if(request.getParameter("pass")!=null && request.getParameter("pass1")!=null){
       String passw1=(String)request.getParameter("pass");
       String passw2=(String)request.getParameter("pass1");
       if(passw1.equals(passw2)){
         //equal
       }
}
   %>

Is it ok or you try to explain other thing?

没关系,或者你试着解释其他事情?

#2


1  

Use .equals() method to check equal String, and apply == for values

使用.equals()方法检查相等的String,并对值应用==

<%
      String passw1=(String)request.getParameter("pass");
       System.out.println("value of passw1"+passw1); // if null let me know
      String passw2=(String)request.getParameter("pass1");
       System.out.println("value of passw2"+passw2); // if null let me know
      if(passw1.equals(passw2)){ //both string match
              //your logic
             System.out.println("string match");
        }
        else{
             System.out.println("string not match");
        }
%>

#1


2  

Scriplet accept java code so its simple like this

Scriplet接受java代码,所以它很简单

    <% 
 if(request.getParameter("pass")!=null && request.getParameter("pass1")!=null){
       String passw1=(String)request.getParameter("pass");
       String passw2=(String)request.getParameter("pass1");
       if(passw1.equals(passw2)){
         //equal
       }
}
   %>

Is it ok or you try to explain other thing?

没关系,或者你试着解释其他事情?

#2


1  

Use .equals() method to check equal String, and apply == for values

使用.equals()方法检查相等的String,并对值应用==

<%
      String passw1=(String)request.getParameter("pass");
       System.out.println("value of passw1"+passw1); // if null let me know
      String passw2=(String)request.getParameter("pass1");
       System.out.println("value of passw2"+passw2); // if null let me know
      if(passw1.equals(passw2)){ //both string match
              //your logic
             System.out.println("string match");
        }
        else{
             System.out.println("string not match");
        }
%>