Problem with comparing strings, with a variable that has the value from a post and one assigned.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jay_Ross
Posted On:   Monday, December 17, 2001 09:06 AM

When I receive a value from a some posted data and compare it to another string with seemingly the same variable they aren't equal for some reason. Example: url: http://www.mysite.com/savedata.jsp?txtFName=Bill&txtLName=Gill code: String FirstName = request.getParameter("txtFName"); String LastName = request.getParameter("txtLName"); if (LastName == Gill) {out.print("Sorry No Data);} For some reason this doesn't work, no idea why, any ideas Thanks in advanced for any help    More>>

When I receive a value from a some posted data and compare it to another string with seemingly the same variable they aren't equal for some reason.


Example:



url: http://www.mysite.com/savedata.jsp?txtFName=Bill&txtLName=Gill



code:

String FirstName = request.getParameter("txtFName");

String LastName = request.getParameter("txtLName");


if (LastName == Gill) {out.print("Sorry No Data);}



For some reason this doesn't work, no idea why, any ideas


Thanks in advanced for any help

   <<Less

Re: Problem with comparing strings, with a variable that has the value from a post and one assigned.

Posted By:   Benoit_Quintin  
Posted On:   Monday, December 17, 2001 09:09 AM

Have you tried .equals() ?? Because, unless your strings are intern()ed, the == won't ever return true.
About | Sitemap | Contact