
i need the source code to display the msgbox in jsp....but one condition is,i need to use it in the current page itself...now i use the message box means it prints it into another page...i need to resolve it plz try to help me..

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);
}
%>

it is tough to understand the code simply i need is first i have to validate whether all the fields are filled . if filled it has to move to the corresponding jsp file else it has to show an alert box that the particular field is not filled