This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes How to compare two strings in value. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to compare two strings in value." Watch "How to compare two strings in value." New topic
Author

How to compare two strings in value.

sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
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

Joined: Jan 10, 2002
Posts: 60752
    
  65

If the expression evaluates to false, the strings are not equal.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 10, 2002
Posts: 60752
    
  65

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

Joined: Feb 18, 2011
Posts: 208
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

Joined: Jan 10, 2002
Posts: 60752
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to compare two strings in value.
 
Similar Threads
assign multiple values to string
Comparing Objects containing List
Bubble Sort Set using Comparator
Stringtokenizer
StringBuffer