a m

Greenhorn
+ Follow
since Feb 25, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by a m

i dont know how to change it
23 years ago
I was wondering how most websites maintain user's login state. Do they usually place a cookie on the user's hard drive or are they somehow maintaining the state somewhere on the server side?
I know that for some sites there's a 'save password' (such as this forum) and that gets done using a cookie. But how do some other sites reset to "logged off" state when the user closes the browser's window or clicks 'log out'??
Thanks I'd appreciate any advice on this issue because I need to implement this functionality using JSP.
23 years ago
OK, it works now that I've initialized the login/pass to "" in the construcotr. however I still haven't completed what I REALLY wanted to do
I wanted to do it this way. Pls tell me if it's doable.
In the JSP, before the login form, I would have :
<%
if (abean.getLogin()!="" && abean.getPass()!="") {
if (abean.getAuthenticate()) {
// it's valid so redirect to some page
} else {
out.println("Error.. Please reenter form data");
}
}
%>
Almost everything works this way. When it first comes to the page I get the login/password prompt. When the two fields are not equaal the error message is shown. When the two fields are equal I get forwarded to the other file.
The problem arises when the user clicks on submit with both fields empty, it still gets forwarded! why does this happen and how can i correct it? Thanks.
Or if u have a better idea of doing his with a small number of JSPs then please let me know.
23 years ago
OK, I've initialized login and pass to a non-null value and it seems to work but I'm working to get a working login screen.
I wanted to do it this way. Pls tell me if it's doable.
In the JSP, before the login form, I would have :
<% if (abean.getAuthenticate()) {
// it's valid so redirect to some other page
} else {
out.println("Error.. Please reenter form data");
}
%>
The problem is -- say I initialize login and password to "" in the LoginHandler constructor, then the first time the user enters the page it will automatically redirect to some page. So I don't want the code to execute the first time, but all subsequent times but I don't see how this can be done. I would like this functionality with the least number of JSPs possible.
Any suggestions?
Thanks,
Mohap.
23 years ago

Originally posted by Sandeep Jain:
Hello,
There are two bugs in ur program .
1) u have set the property of password as setPass() and not setPassword()
2)U have to make use of equals method and not == in the authenticate method which returns the boolean value.
Change these things i ur program and it will work fine.



I changed these things but now at the line
return (login.equals(pass))
It gives me a nullpointerexception?? why?
23 years ago
I have been pulling my hair out for way too long on this one - 4 hours for
something that's supposed to be "simple"
Here goes--
I've written a login JSP page. It's supposed to say "Hi,Foobar" whenever the
login name is _equal_ to the password but it only does this the first time I
enter the page, not subsequent times. And it's supposed to just print "Hi, "
below the form whenever they're not equal. It does this all the time though.
What could be the problem?
Here's the JSP with the form in it -- login.jsp --
<jsp:useBean id="abean" scope="session" class="LoginHandler" />
<jsp:setProperty name="abean" property="*" />
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="logon" method="post">
<p>Login
<input type="text" name="login">
</p>
<p>Password
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<h1>Hello, <% if (abean.getAuthenticate()) out.println("Foobar"); %>
</h1>
</body>
</html>
Now here's the class 'LoginHandler':
--LoginHandler.java--
public class LoginHandler {
String login;
String pass;
boolean authenticate;
public LoginHandler() {
login = null;
pass = null;
}
public void setLogin(String name ) {
login = name;
}
public String getLogin() {
return login;
}
public void setPassword(String password) {
pass = password;
}
public String getPass() {
return pass;
}
public boolean getAuthenticate() {
return (login==pass);
}
}
23 years ago