Check for empty session variable

Hey there we're making a login for our jsp web application.

The login allready works and so does the log out but now we want to make a check to make it impossible to login with names that are not in the database.

So what basicly happens is as follows...

Login reads the database info:

while (rs.next()){

if (request.getParameter("username").equals(rs.getString("username")) && request.getParameter("password").equals(rs.getString("password"))){

session.setAttribute("username", rs.getString("username"));

session.setAttribute("firstname", rs.getString("first_name"));

session.setAttribute("lastname", rs.getString("last_name"));

}

}

but when you enter invalid information teh session variabe "lastname" for example should readnull. Now we want to make a check for this null value, which should look something like this:

if(session.getAttribute("username").equals(null)){

response.setStatus(301);

response.setHeader("Location","/index.jsp");

}else{

response.setStatus(301);

response.setHeader("Location","/mainmenu.jsp");

}

But this doesnt work, it just logs in with the null values... any1 got a clue?

edit: im actually looking for something like the isSet command in PHP to give an idea...

Message was edited by:

whappit

[2131 byte] By [whappita] at [2007-10-2 19:40:10]
# 1
Your test for null will always fail, because request.getParameter("username") is NEVER null, in that it exists, even though it contains no data.Try .equals(""); instead.
angrycata at 2007-7-13 22:18:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...