aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax in JSP" Watch "Ajax in JSP" New topic
Author

Ajax in JSP

arjun kt
Greenhorn

Joined: Feb 14, 2009
Posts: 5
hii friendz ma problem is am using ajax for populating user id and name from data base my sql..... bt d datas are not coming please help mi... ma codes are below
arjun kt
Greenhorn

Joined: Feb 14, 2009
Posts: 5
<%@ page import="java.sql.*" %>
<html>
<head>
<script type="text/javascript">
function showUser(user_value)
{
if(document.getElementById("user_id").value!="-1")
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.jsp"
url=url+"?user_id="+user_value

xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}
else
{
alert("Please Select User Id");
}
}

function stateChanged()
{
document.getElementById("username").value ="";
document.getElementById("user_id").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

var showdata = xmlHttp.responseText;
var strar = showdata.split(":");

if(strar.length==1)
{
document.getElementById("user_id").focus();
alert("Please Select User Id");
document.getElementById("username").value =" ";
document.getElementById("user_id").value =" ";

}
else if(strar.length>1)
{
var strname = strar[1];
document.getElementById("User_id").value= strar[2];
document.getElementById("username").value= strar[1];
}

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>

</head>
<body>
<form name="user">
<br><br>
<table border="0" width="400px" align="center" bgcolor="#CDFFFF">
<div id="mydiv"></div>
<tr><td><b>Select User Id</b></td><td>
<select name="suser_id" onchange="showUser(this.value);">
<option value="-1">Select</option>
<%

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "user_register";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";

int sumcount=0;
Statement st =null;
try {
Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName,userName,password);
String Query = "select * from knp_usermaster";

st = conn.createStatement();
ResultSet rs = st.executeQuery(Query);
%>

<%
while(rs.next())
{
%>

<option value="<%=rs.getString(1)%>"><%=rs.getString(1)%></option>

<%
}
%>

<%

}
catch (Exception e) {
e.printStackTrace();
}

%>

</select>
</td></tr>


<tr><td><b>User Id:</b></td><td><input type="text" name="user_id" id="user_id" value=""></td></tr>
<tr><td><b>UserName:</b></td><td><input type="text" name="user_name" id="user_name" value=""></td></tr>

</table>
</form>

<table border="0" width="100%" align="center">


<br>
<br>


</table>
</body>
</html>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

"arjun kt", firstly, please check your private messages for an important administrative matter. Again.

Also, please use real words when posting to the forums. Abbreviations such as "p=plz" in place of "please" only serve to make your posts more difficult to read and less likely to generate useful responses. Please read this for more information.

And finally, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax in JSP