Solved

Strange thing

Posted on 2004-03-24
2
181 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Primefaces: How to display a variable that can take only 'Y' or 'N' or a boolean value. 2 124
library class in java 1 93
withoutString  challenge 40 207
runtime exception 2 41
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 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