Divya,
You were probably a C++ programmer in a past life like myself. I made this
mistake myself when I first went from C++ to Java. The operator overloading
for string comparisons that you can rely on in C++ to compare two strings by
value doesn't work in Java. Java doesn't support operator overloading. So,
you are actually comparing two objects by reference and not by value. The
two references must be the same (i.e., refer to the exact same object) for
the comparison to return true. So, the values could both be "1" and the
result can still be false when the object each refers to is different (as is
the case in your example).
I think you want your test coded something like this:
String val = request.getParameter("val");
if (val.equals("1"))
Hope This Helps,
Mike Van Riper
> -----Original Message-----
> From: Divya M A [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 27, 2000 1:34 PM
> To: [EMAIL PROTECTED]
> Subject: Using query string values in JSP
>
>
> Hi!
> I'm new to JSP. I have a JSP file which must perform a
> task depending on
> the value passed through a query-string in the url. But I am
> not able to
> make the comparison;i.e,
> if my url is : 'first.jsp?val=1'
> and in the jsp file, I check the value of the string passed
> as shown below:
> if (request.getParameter("val") == "1")
> {
> ---------
> }
> This condition is not true though my query string is 'val=1', which I
> understand is a string and the above compare should work fine.
> My guess was that probably the query string includes a terminator or
> something similar which is not in the hard-coded value("1"),
> but on checking
> the length after assigning both to string variables, the
> lengths were the
> same. Please note that the comparison of these string
> variables too gave me
> a negative result.
> Please help.
>
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets