
Hi
how to send an error message to an html page after checking the database for different users.for eg:your user name or password is incorrect.reply me with code, without using bean.

1)login.jsp:
<html>
<head>
<script type="text/javascript">
function showData(){
var user=document.getElementById("username").value;
var pass=document.getElementById("password").value;
xmlHttp=GetXmlHttpObject()
var url="checkajax.jsp";
url=url+"?user="+user+"&&pass="+pass;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var showdata = xmlHttp.responseText;
alert(showdata);
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<form name="form">
<table>
<tr><td>Username:</td><td><input type="text" id="username"></td></tr>
<tr><td>Password:</td><td><input type="password" id="password"></td></tr>
<tr><td></td><td><input type="button" value="Submit" onclick="showData();"></td></tr>
</table>
</form>
</html>
2)checkajax.jsp:
<%@ page import="java.sql.*" %>
<%
String user = request.getParameter("user");
String pass = request.getParameter("pass");
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
while(rs.next())
{
count++;
}
if(count>0)
{
data="Welcome User!";
}
else
{
data="Username or Password is Invalid!";
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.