Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


amruta bharat gat
hiiiiiiiiii
1 Answer(s)      2 years and a month ago
Posted in : JSP-Servlet


code for how to search contacts in mobile phone using servlet and jsp??for e.g. when we click on letter a the all contacts starting with a should be displayed.....


Advertisement
View Answers

July 25, 2012 at 11:51 AM


Here is a simple jsp code that displays the contact numbers started with the given number.

1)auto.jsp:

<%@page import="java.sql.*"%>
 <html>
 <head>  
 <script language="javascript" type="text/javascript">  
 var xmlHttp  
 var xmlHttp
 function showState(str){ 
if (typeof XMLHttpRequest != "undefined"){
   xmlHttp= new XMLHttpRequest();
       }
       else if (window.ActiveXObject){
   xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
       }
if (xmlHttp==null){
    alert ("Browser does not support XMLHTTP Request")
return
} 
var url="get.jsp";
url += "?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
 function stateChange(){   
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
 document.getElementById("div").innerHTML=xmlHttp.responseText;  
 }   
 }   
 </script>  
 </head>  
 <body>  
 <input id="name" type="text" name="name" onkeyup="showState(this.value)">
 <br>  
 <div id='div'>  
 </div>  
 </body> 
 </html>

2)get.jsp:

<%@page language="java" import ="java.sql.*" %>  
 <%  
 String name=request.getParameter("count");  
 String buffer="<div>";  
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from person where contactNo LIKE '"+name+"%'");  
   while(rs.next()){
   buffer=buffer+rs.getString("contactNo")+"<br>";  
   }  
 buffer=buffer+"</div>";  
 response.getWriter().println(buffer);  
 %>


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com