Respected Sir,
I am trying to execute above code with rerquest response object. In my
jsp file i have 3 text boxes 1.mobile 2.username 3.password ,
All the above three attributes are stored in MySql table emp.
I want to execute this code in a fashion like when i entered the mobile number in text box
the values of other attributes like username and password should be automatically retrieved
in respective text boxes. if for solving above problem servlet needed then help me with that
also.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import ="java.sql.*;" %>
<html>
<script language="javascript">
function validate()
{
if(document.loginname.user.value=="")
{
alert("Please Enter Username");
document.loginname.user.focus();
document.loginname.user.select();
}
else if(document.loginname.passw.value=="")
{
alert("Please Enter Password");
document.loginname.passw.focus();
document.loginname.passw.select();
}
else
{
document.loginname.submit();
}
}
</script>
<form name="loginname" method="post" >
<body>
<% if (request.getParameter("msg") != null )
{
%>
<table align="center"><tr><td>
<center><font color="#993300" style="font-family:Verdana, Arial, Helvetica,
sans-serif; font-size:12px">Connection Reset.Try Again.</font></center>
</td></tr></table>
<%
}
%>
<% if (request.getParameter("logmsg") != null )
{
%>
<table align="center"><tr><td>
<center><font color="#993300" style="font-family:Verdana, Arial, Helvetica,
sans-serif; font-size:12px">Invalid Login Data.Try Again.</font></center>
</td></tr></table>
<%
}
%>
<br>
<table width="300px" align="center" cellpadding="5" cellspacing="5">
<tr><td>Insert Mobile Number: </td><td><input type="text" name="mobile"/></td></tr>
<tr><td>Username: </td><td><input type="text" name="empuser" /></td></tr>
<tr><td>Password: </td><td><input type="password" name="emppassw"
/></td></tr>
<tr>
<td colspan="2">
<center>
<input type="button" onClick="validate()" value="Submit"/>
<input type="reset" value="reset" />
</center>
</body>
</form>
<script language="javascript">
function usernameandpass()
{
<%! String str;%>
<%! int id2;%>
<%! Connection con = null;%>
<%! Statement st = null;%>
<%! ResultSet rs = null;%>
<%
String str=request.getParameter("mobile");
System.out.print(str);
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
// String mobile=request.getParameter("mobile");
} catch (ClassNotFoundException ce) {
out.println(ce);
}
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/online",
"root", "root");
st = con.createStatement();
rs = st.executeQuery("Select * from emp where mobile="+mobile" ");
while (rs.next()) {
id2 = rs.getInt(1);
}
id2++;
rs.close();
st.close();
con.close();
} catch (SQLException exception) {
}
System.out.print(id2);
%>
document.write(mobile);
}
</script>
</html>