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 Servlets and the fly likes WHAT THE $%#^%# IS HAPPENING HERE? 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 » Servlets
Bookmark "WHAT THE $%#^%# IS HAPPENING HERE?" Watch "WHAT THE $%#^%# IS HAPPENING HERE?" New topic
Author

WHAT THE $%#^%# IS HAPPENING HERE?

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Im about as aggravted as I can be right now with a log in servlet that Ive been getting some null pointer exceptions from. They only happen once & a while so I looked at my logs & saw that 2% of the visitors were using non javascript enabled browsers...OK, that makes sense. So I threw some logic into the log in servlet to handle this. This is what I threw in:
String userName = null;
String passWord = null;
int nullTrigger = 0;
if ((req.getParameter("userName") != null) && (req.getParameter("userName") != " ")) {
userName = req.getParameter("userName").toUpperCase();
nullTrigger = 1;
}
if ((req.getParameter("passWord") != null) && (req.getParameter("passWord") != " ")) {
passWord = req.getParameter("passWord").toUpperCase();
nullTrigger = 1;
}
if (nullTrigger == 1){
// normal db log in code stuff
}
Easy fix right? Not so fast the buddy...I took the validation Javascript out of the page that the user enters their log in info so i could force this error.......the %$#%^$# thing still manages to make it into the if (nullTrigger == 1) block!!!
Ive fought with this thing for 3 hours & I cant get it to stop......what in heavens name is going on here...If the textboxes for the log in are empty they should come thru as null ......RIGHT??? I could sure use another opinion on this one..Im as frustrated as i can be here! BTW Here's the form thats accessing this (figured someone might ask):
<FORM METHOD=POST ACTION="/servlet/logIn" CLASS=blueT>
<input type="text" name="userName" size="10"><br>
Username<br> <br>
<input type="password" name="passWord" size="10"><br>
Password
<br> <br>
<input type="submit" value="Log In">
</FORM>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Actually it hightlights the fact that I've never tested but there might be a bit of client and app server dependence here.
I always check for the empty string as well as null when testing valid values.

The other trap you're falling in is the '==' (or != in your case) versus .equals for String equality...
Dave.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Boy you got me on that one....I should be asshamed of myself for the == .......yeesh, I guess that's what happens when you get aggravated, cant see the trees for the forest. Time to retest!
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Thanks again Dave......Works fine. Just goes to show that you should take a walk when aggravated because you'll come back & see something stupid like that, either that or always have another pair of eyes to look at your code....One thing good has come out of it. Im now a firm believer in .trim()!
[This message has been edited by DC Dalton (edited August 28, 2001).]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I've made sure I've forgotten what it is I actually did, but I did stop yesterday and think "I can't believe I actually did that".
It might have something to do with using non-Java comments for some reason, like using the TCL ones even thought I haven't touched TCL in ever such a long time..
I think it comes down to the Dilbert Principle: Everyone is an idiot at some stage, even me.

Dave.
 
 
subject: WHAT THE $%#^%# IS HAPPENING HERE?
 
Similar Threads
A null pointer that I dont quite understand
Servlet
servlet problem
Need Help With Dynamic text box in JSP
req.setAttribute problem