Solved

Strange thing

Posted on 2004-03-24
2
180 Views
Last Modified: 2010-04-01
Hi Experts,

I have simple code in JSP:

String idText = request.getParameter( "id" );

        if ( idText == "test" )
        {
           out.println( "searching in test" );
        }
        else
        {
           out.println( "searching in prod" );
        }

for some reason it always go to  out.println( "searching in prod" ); even when I have "test" in idText.

Please help.
0
Comment
Question by:fpoyavo
  • 2
2 Comments
 
LVL 8

Expert Comment

by:william_jwd
ID: 10668183
you should change the code to
String idText = request.getParameter( "id" );

        if ( idText.equals("test") )
        {
           out.println( "searching in test" );
        }
        else
        {
           out.println( "searching in prod" );
        }
0
 
LVL 8

Accepted Solution

by:
william_jwd earned 500 total points
ID: 10668189
you can also use, equalsIgnoreCase if you want to compare ignoring case

String idText = request.getParameter( "id" );

        if ( idText.equalsIgnoreCase("test") )
        {
           out.println( "searching in test" );
        }
        else
        {
           out.println( "searching in prod" );
        }
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lamba in java 8 9 244
AlarmClock Challenge 35 150
Handle form fields in spring mvc controller 1 65
how to add new optional parameter to JSP 1 42
An article on effective troubleshooting
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question