April 4, 2003

If STRING = "TEXT" for Java Server Pages

Okay. I'm not a super-duper-cool-Java-coder. I'm still learning. My main problems always arise from trying expressions/variables/stuff from other languages and not having it work. And let me tell you, JSP(Java Server Pages) Error Messages are the most cryptic fucking annoying things in the world.

So, to get to the point. I have a variable I was passing in. To sort a table. So I had to do two things. 1) See if the variable existed, and if not, give it a default value. 2) If it did, in fact, exist, assign the table name that the SQL(Structured Query Language) was going to call in the query.

Silly me, I thought that if (variable == "passedInVariable") would work. Stupid me. I mean, sure, it works for if variable != null). But not for checking to see if two strings are the same.

if (variable.equals("FOO"))
    NewVariable = "tableFOO";
else if (variable.equals("BAR"))
    NewVariable = "tableBAR";
else
    NewVariable = "tableDEFAULT";

Yup. variable.equals("text") is the key.

Post Info

Tagged As Coding

Comments are Open (4)

Posted at 03:13 PM

Comments

Lucas

Thank you for posting this. I've been dicking around with the same problem for the past hour.

Tony

Glad I could help. Whenever I run across some problem that's been kicking my ass like this, I generally try and post my solution, if I remember. Remembering is the key.

eddie

Thank you for that!

I spend hours of hours trying to make a script with the wrong syntaxis...

eddie.

amanda

LoL hey thanks, man ;) u's tops!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu