• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compare two strings in value.

 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I pass in 2 values from a controller to a jsp file. They are in String types.
I need to compare them in value.

The following statement always return false:



I have looked into EL section, but it doesn't really explain how to compare 2 string parameters in values.

Any suggestion is very appreciated.
Thanks
Sam

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the expression evaluates to false, the strings are not equal.
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you think they are equal and the "eq" operator says they are not, then it's time for some debugging. Perhaps there is some white-space at the end of one of the strings which is not at the end of the other. Perhaps there are upper/lower-case differences which you didn't notice, or extra white-space in the middle of one.

And remember that HTML (which is what you will be generating) hides a lot of the white-space you put in it. Don't let that interfere with your debugging.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just print below statements in jsp. and see what they print.

if both print same value then as paul suggested you may need to go further...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:just print below statements in jsp. and see what they print.

In my opinion, that's a waste of time. using HTML output for debugging is just too error-prone to be worth the effort. Spend the time debugging the issue for real on the server.
 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If the expression evaluates to false, the strings are not equal.

They are passing it as string, but I need to compare them as numeric or number.
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam White wrote:
Bear Bibeault wrote:If the expression evaluates to false, the strings are not equal.

They are passing it as string, but I need to compare them as numeric or number.
Thanks

Well that's completely different than what you originally posted.

But it's also moot. If the strings are equal it doesn't matter what's in them. Equals is equals. Now if you want to do greater/lesser comparison, that's different.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic