Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Ajax in JSp

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
<%@ 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>
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Arjun Kt wrote: hii friendz ma ...... bt d datas ..... mi... ma codes are below


Please UseRealWords

You have to tell the details, Where are you facing problem, Have you tried to use multiple "alert()' statement to debug, where its going wrong ?

One suggestion, Use it readyState once, like



And please use CodeTags
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
I didn't say it. I'm just telling you what this tiny ad said.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    Bookmark Topic Watch Topic
  • New Topic