Solved

Strange thing

Posted on 2004-03-24
2
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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