if( Password1 != Password2 )
In java the above code check if the reference of Password1 is not = to the
reference of Password2 which will always be the case in your code. The content
of Password1 is not check against the content of Password2. What you need is the
following if (Password1.equals(Password2) == false). Now if Password1 is a null
object you will get a null pointer exception becaue you cannot execute methods
on a null object. A java programming course might be helpful
"Oliver Kaljuvee" <[EMAIL PROTECTED]> on 08/24/99 05:49:54 AM
Please respond to "Oliver Kaljuvee" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Robert Voysey/Inv/MetLife/US)
Subject: Problem in the code...
Hi Everybody,
I am testing out a simple form that takes four values. The starting page is
called test.jsp, which has an action to process.jsp (the code below). The
insertion to the database works fine, however, the code has a flaw when checking
for the passwords; it always considers the passwords being different; in other
words it keeps going in a loop.
For instance, when on test.jsp I fill in the values; it will go to process.jsp
and always executes the code after the if-statement regardless whether the
passwords were identical or not. Can anyone see right off the back what the
problem might be?
Thank you in advance.
-- Oliver
<HTML>
<HEAD>
<TITLE>TestResults</TITLE>
</HEAD>
<BEAN NAME="jspDb"
TYPE="com.livesoftware.jrun.plugins.jsp.beans.JSPDBConnection" SCOPE="session">
</BEAN>
<!--#include file="dbsettings.jsp"-->
<%
// declare variables
String FirstName = "";
String LastName = "";
String Password1 = "";
String Password2 = "";
String sql = "";
// set up the database connection
jspDb.setDriver(JDBC_DRIVER);
jspDb.setUrl(JDBC_URL);
jspDb.setPoolSize(JDBC_POOLSIZE);
jspDb.setUser(JDBC_USR);
jspDb.setPass(JDBC_PWD);
jspDb.open(JDBC_DBNAME);
// get the values from the form
FirstName = ((String) Request.Form("FirstName"));
LastName = ((String) Request.Form("LastName"));
Password1 = ((String) Request.Form("Password1"));
Password2 = ((String) Request.Form("Password2"));
if( Password1 != Password2 )
{
// this the html from the starting page (test.jsp):
%>
<html>
<body>
</head>
<body>
<form NAME="register" METHOD="POST" ACTION="process.jsp">
<h1>The passwords have to be identical!</h1><br><br>
FNM: <input type="text" name="FirstName" size=20>*<br>
LNM: <input type="text" name="LastName" size=20>*<br>
PWD: <input type="password" name="Password1" size=20><br>
PWD: <input type="password" name="Password2" size=20><br><br>
* Required Fields<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<% }
else
{
sql = "INSERT INTO test (UserID, FirstName, LastName, Password1, Password2)
values " +
"(DEFAULT, '" + FirstName + "', '" + LastName + "', '" + Password1 + "'," +
"'" + Password2 + "')";
jspDb.setSql(sql);
JSPDBResult[] rs = jspDb.execute();
}
%>
Password 1:
<%= Password1 %>
<p>
Password 2:
<%= Password2 %>
<p>
<center>Thank you for submitting...</center>
</HTML>
Hi Everybody,
I am testing out a simple form that takes four values. The
starting page is called test.jsp, which has an action to process.jsp (the
code below). The insertion to the database works fine, however, the code
has a flaw when checking for the passwords; it always considers the passwords
being different; in other words it keeps going in a loop.
For instance, when on test.jsp I fill in the values; it will go
to process.jsp and always executes the code after the if-statement regardless
whether the passwords were identical or not. Can anyone see right
off the back what the problem might be?
Thank you in advance.
-- Oliver
<HTML>
<HEAD>
<TITLE>TestResults</TITLE>
</HEAD>
<BEAN NAME="jspDb" TYPE="com.livesoftware.jrun.plugins.jsp.beans.JSPDBConnection"
SCOPE="session">
</BEAN>
<!--#include file="dbsettings.jsp"-->
<%
// declare variables
String FirstName = "";
String LastName = "";
String Password1 = "";
String Password2 = "";
String sql = "";
// set up the database connection
jspDb.setDriver(JDBC_DRIVER);
jspDb.setUrl(JDBC_URL);
jspDb.setPoolSize(JDBC_POOLSIZE);
jspDb.setUser(JDBC_USR);
jspDb.setPass(JDBC_PWD);
jspDb.open(JDBC_DBNAME);
// get the values from the form
FirstName = ((String) Request.Form("FirstName"));
LastName = ((String) Request.Form("LastName"));
Password1 = ((String) Request.Form("Password1"));
Password2 = ((String) Request.Form("Password2"));
if( Password1 != Password2 )
{
// this the html from the starting page (test.jsp):
%>
<html>
<body>
</head>
<body>
<form NAME="register" METHOD="POST" ACTION="process.jsp">
<h1>The passwords have to be identical!</h1><br><br>
FNM: <input type="text" name="FirstName" size=20>*<br>
LNM: <input type="text" name="LastName" size=20>*<br>
PWD: <input type="password" name="Password1" size=20><br>
PWD: <input type="password" name="Password2" size=20><br><br>
* Required Fields<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<% }
else
{
sql = "INSERT INTO test (UserID, FirstName, LastName, Password1,
Password2) values " +
"(DEFAULT, '" + FirstName + "', '" + LastName + "', '" +
Password1 + "'," +
"'" + Password2 + "')";
jspDb.setSql(sql);
JSPDBResult[] rs = jspDb.execute();
}
%>
Password 1:
<%= Password1 %>
<p>
Password 2:
<%= Password2 %>
<p>
<center>Thank you for submitting...</center>
</HTML>
oliver.kaljuvee.vcf