CODES:
form
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>LogIn Form</title>
<script language="javascript">
function ChkLogin() {
var message;
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
if (username=="" || password=="") {
if (username=="" && password=="") {
message = "Please input your username and password.";
} else if (username=="") {
message = "Please input your username.";
} else if (password =="") {
message = "Please input your password.";
}
alert(message);
return false;
} else {
return true;
}
}
</script>
<style type="text/css">
<!--
.style3 {font-family: "Courier New", Courier, monospace; font-size: small; }
.style4 {font-size: small}
-->
</style>
</head>
<body>
<form id="form1" name="frmLogIn" method="post" action="ValidateUser.jsp" onsubmit="return ChkLogin(this);">
<table width="269" border="0" align="center">
<tr>
<td width="100"><span class="style3">Username:</span></td>
<td width="159"><input name="username" type="text" size="25" maxlength="15" /></td>
</tr>
<tr>
<td><span class="style3">Password:</span></td>
<td><input name="password" type="password" size="25" maxlength="15"/></td>
</tr>
<tr>
<td><span class="style4"></span></td>
<td><span class="style3">
<input type="submit" name="btnSubmit" value="Submit"/>
<input type="reset" name="btnReset" value="Reset" />
</span></td>
</tr>
</table>
</form>
</body>
</html>
validate
<%
String userName = request.getParameter("username");
String password = request.getParameter("password");
if (userName != "Jose") {
out.println("You have entered an invalid username. " + userName);
%>
<br/>
<span class="style3">Click <a href="LogIn.jsp">here</a> to re-login.</span>
<%
} else {
out.println("Welcome " + userName + "!");
}
%>
our problem is with the validation. We got a wrong output. If we put anything (even the 'Jose' username) we have the invalid message...
what's wrong with our code? can someone checked on it...
Thanks in advance.

New Topic/Question
Reply




MultiQuote



|