java 如何在JSP中检查两个字符串是否相等?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39343753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:17:55  来源:igfitidea点击:

How to check two strings are equal in JSP?

javastring-comparison

提问by dharan

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");

回答by Jekin Kalariya

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?

可以吗,或者您尝试解释其他事情?

回答by yash

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");
        }
%>